<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: localhost code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 00:09:51 GMT</pubDate>
    <description>DZone Snippets: localhost code</description>
    <item>
      <title>Run TCPServer as a simple Web server</title>
      <link>http://snippets.dzone.com/posts/show/5345</link>
      <description>A TCPServer accepts incoming TCP connections. Here is a Web server that listens on a given port and returns the time.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'socket'&lt;br /&gt;port = (ARGV[0] || 80).to_i&lt;br /&gt;server = TCPServer.new('localhost', port)&lt;br /&gt;while (session = server.accept)&lt;br /&gt;  puts "Request: #{session.gets}"&lt;br /&gt;  session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"&lt;br /&gt;  session.print "&lt;html&gt;&lt;body&gt;&lt;h1&gt;#{Time.now}&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;\r\n"&lt;br /&gt;  session.close&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This code was copied from &lt;a href="http://www.rubycentral.com/pickaxe/lib_network.html"&gt;Programming Ruby: The Pragmatic Programmer's Guide&lt;/a&gt; [rubycentral.com] while looking for information on Ruby CGI global variables.</description>
      <pubDate>Thu, 10 Apr 2008 14:05:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5345</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
