Skip to content

Instantly share code, notes, and snippets.

@yannski
Created May 30, 2010 11:11
Show Gist options
  • Save yannski/418952 to your computer and use it in GitHub Desktop.
Save yannski/418952 to your computer and use it in GitHub Desktop.
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