Skip to content

Instantly share code, notes, and snippets.

@Poincare
Created August 5, 2012 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Poincare/3266914 to your computer and use it in GitHub Desktop.
Save Poincare/3266914 to your computer and use it in GitHub Desktop.
require 'socket'
require 'celluloid'
class AnswerActor
include Celluloid
def initialize(client)
@client = client
end
def start
@client.puts
headers = "HTTP/1.1 200 OK\r\nDate: Tue, 14 Dec 2010 10:48:45 GMT\r\nServer: Ruby\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n"
@client.puts headers
@client.puts "<html></html>"
loop {
#kind of just hang around and block the actor
}
end
end
class HTTPServer
include Celluloid
def initialize(port)
@port = port
end
def start
@server = TCPServer.new(@port)
loop {
aa = AnswerActor.new @server.accept
puts "waddup"
aa.start!
}
end
end
hs = HTTPServer.new 3000
hs.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment