Created
May 30, 2010 11:11
-
-
Save yannski/418952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Room < EM::Channel | |
def say(nick, type, text = nil) | |
# some code here to build the string that will be sent back | |
push(str) | |
end | |
end | |
class LongPollHttpServer < EM::Connection | |
def receive_data(data) | |
case path | |
when '/recv' | |
@subscription = $room.subscribe do |msg| | |
respond msg, 200, "application/json" | |
end | |
end | |
end | |
RESPONSE = [ | |
"HTTP/1.1 %d PLOP", | |
"Content-length: %d", | |
"Content-type: %s", | |
"Connection: close", | |
"", | |
"%s"].join("\r\n") | |
def respond(body, status = 200, content_type = 'text/comet') | |
send_data RESPONSE % [status, body.length, content_type, body] | |
close_connection_after_writing | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment