9. Under the hood
Nginx HTTP_Push_Module
Long polling
Push handled by separate component
Worked, but fiddly to setup
10. Makoto
WebSockets
http://www.flickr.com/photos/lenaah/2939721384/
December 2009
11. WebSockets
HTML5 sub standard
Allows Socket in the browser
Now supported in the ‘non-shite’
browsers
Chrome & Webkit (nightly)
There is a library for flash emulation
12. Ajax vs Comet vs WebSocket
Server
Ajax
(Polling)
Client
Server
Comet
(Long polling)
Client
Server
WebSocket
Client
20. class Connection
class << self
def add(websocket)
connections << websocket
end
def all
connections
end
def remove(websocket)
connections.delete(websocket)
end
private
def connections
@connections ||= []
end
end
end
Keep connection objects in memory
21. EventMachine.run {
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 3001) do |ws|
ws.onopen {
puts "WebSocket connection open"
Connection.add(ws)
}
ws.onclose { Connection.remove(ws) }
ws.onmessage { |data|
Connection.all.each do |ws|
ws.send(data) unless ws == self
end
}
end
}