• Save
Websockets and Ruby EventMachine
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Websockets and Ruby EventMachine

on

  • 26,619 views

The basics of a WebSockets server in Ruby EventMachine and your own custom JSON protocol for Events-centric WebSockets programming....

The basics of a WebSockets server in Ruby EventMachine and your own custom JSON protocol for Events-centric WebSockets programming.

See more at http://blog.new-bamboo.co.uk/2010/2/10/json-event-based-convention-websockets

Statistics

Views

Total Views
26,619
Views on SlideShare
26,462
Embed Views
157

Actions

Likes
43
Downloads
0
Comments
3

11 Embeds 157

http://www.slideshare.net 136
http://www.plurk.com 6
http://135.9.182.117:4000 4
http://www.pinterest.com 2
http://localhost:3000 2
http://135.9.32.60:4000 2
http://www.instacurate.com 1
http://pinterest.com 1
http://a0.twimg.com 1
http://webcache.googleusercontent.com 1
http://www.verious.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Should be downloadable…
    Are you sure you want to
    Your message goes here
    Processing…
  • zerostar88, indeed, very nice websocket presentation!
    YouTube mp3 http://videotomp3converter.com/
    Are you sure you want to
    Your message goes here
    Processing…
  • Good websocket presentation
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • - WebSockets is a HTML5 standard for server-browser persistent connections <br /> - Bidirectional <br /> - Less overhead than polling and long-polling
  • - callbacks
  • - Browser sends &#x201C;Upgrade&#x201D; request. <br /> - Server &#x201C;upgrades&#x201D; connection to persistent TCP socket. <br /> - No more headers sent.
  • - &#x201C;messages&#x201D; delimited by these hex characters (null and termination) <br /> - incoming message triggers &#x201C;onmessage&#x201D;. <br /> - &#x201C;send&#x201D; method wraps messages internally
  • - listent <br /> - send
  • - Server requirements <br /> - Threads: memory bloat
  • - EventMachine: evented, non-blocking Network connections <br /> - predefined callbacks: post_init, receive_data <br /> - implement servers (HTTP, WebSockets, others)
  • - EM-WebSocket extension by Ilya Grigorik <br /> - Implements WS server, handshake <br /> - WS API callbacks open, message, close
  • - Send messages back to clients
  • - store new connections <br /> - send message to each connection
  • - you can structure you messages however you want. <br /> - pick the right protocol for your domain <br /> - or design your own
  • - custom JSON format: [event, custom_data] <br /> - simple standard for client-side events
  • - structured JSON messages allow neat JS client. <br /> - Browser binds to custom events and manipulates DOM <br /> - Treat server as any DOM element
  • - Send form to sockets server <br /> - Familar Javascript events-centric semantics <br /> - Wrapper sends JSON event convention
  • - Simplified. Trivial <br /> - wraps WebSocket object <br /> - callbacks chain <br /> - JSON encoding - decoding
  • - callback chain <br /> - add one or more handlers to each event name
  • - hook in WebSocket.onmessage() <br /> - JSON-decode <br /> - execute callbacks for each event name
  • Trigger and send event to server <br /> - JSON-encode message to format convention <br /> - [event_name, data]

Websockets and Ruby EventMachine Presentation Transcript

  • 1. WebSockets & Ruby EventMachine HTML5 Web sockets Polling Long-polling Web socket websockets.org/about.html Ismael Celis new bamboo
  • 2. WebSockets & Ruby EventMachine Use cases • Chat (lame) • Stocks (lame) • Games • Presence • Collaboration • Real-time notifications Ismael Celis new bamboo
  • 3. WebSockets & Ruby EventMachine WebSockets DOM API Ismael Celis new bamboo
  • 4. WebSockets & Ruby EventMachine WebSockets handshake Request Response Profit! Ismael Celis new bamboo
  • 5. WebSockets & Ruby EventMachine Messages "x00Hello Worldxff" Ismael Celis new bamboo
  • 6. WebSockets & Ruby EventMachine Real Time HTML Ismael Celis new bamboo
  • 7. WebSockets & Ruby EventMachine (Ruby) WebSockets server • Speak WebSockets (handshake) • Keep connections alive • Performant! • Scalable • Threads? Evented? Ismael Celis new bamboo
  • 8. WebSockets & Ruby EventMachine EventMachine rubyeventmachine.com Ismael Celis new bamboo
  • 9. WebSockets & Ruby EventMachine EM-WebSocket github.com/igrigorik/em-websocket Ismael Celis new bamboo
  • 10. WebSockets & Ruby EventMachine EM-WebSocket github.com/igrigorik/em-websocket Ismael Celis new bamboo
  • 11. WebSockets & Ruby EventMachine Multiuser Ismael Celis new bamboo
  • 12. WebSockets & Ruby EventMachine Pick your format STOMP CONNECT login: <username> passcode: <passcode> <message XMPP from=”john@server.com/ruby” to=”jane@server.com/ruby”> <body>Hey Jane!</body> </message> Your own (JSON?) Ismael Celis new bamboo
  • 13. WebSockets & Ruby EventMachine Custom JSON format [ “user_connected”, Event name { “name” : “Ismael”, “message” : “hello!”, Custom data “total_users” : 10 } ] Ismael Celis new bamboo
  • 14. WebSockets & Ruby EventMachine Javascript wrapper Ismael Celis new bamboo
  • 15. WebSockets & Ruby EventMachine Javascript wrapper [ “user_message”, { “name” : “Ismael”, “message” : “hello!” } ] Ismael Celis new bamboo
  • 16. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 Ismael Celis new bamboo
  • 17. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 Ismael Celis new bamboo
  • 18. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 WebSocket Ismael Celis new bamboo
  • 19. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 Ismael Celis new bamboo
  • 20. WebSockets & Ruby EventMachine blog.new-bamboo.co.uk Ismael Celis new bamboo