Your SlideShare is downloading. ×
  • Like
  • Save
Websockets and Ruby EventMachine
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Websockets and Ruby EventMachine

  • 22,727 views
Published

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

Published in Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Should be downloadable…
    Are you sure you want to
    Your message goes here
  • zerostar88, indeed, very nice websocket presentation!
    YouTube mp3 http://videotomp3converter.com/
    Are you sure you want to
    Your message goes here
  • Good websocket presentation
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
22,727
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
0
Comments
3
Likes
43

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • - WebSockets is a HTML5 standard for server-browser persistent connections
    - Bidirectional
    - Less overhead than polling and long-polling
  • - callbacks
  • - Browser sends “Upgrade” request.
    - Server “upgrades” connection to persistent TCP socket.
    - No more headers sent.
  • - “messages” delimited by these hex characters (null and termination)
    - incoming message triggers “onmessage”.
    - “send” method wraps messages internally
  • - listent
    - send
  • - Server requirements
    - Threads: memory bloat
  • - EventMachine: evented, non-blocking Network connections
    - predefined callbacks: post_init, receive_data
    - implement servers (HTTP, WebSockets, others)
  • - EM-WebSocket extension by Ilya Grigorik
    - Implements WS server, handshake
    - WS API callbacks open, message, close
  • - Send messages back to clients
  • - store new connections
    - send message to each connection
  • - you can structure you messages however you want.
    - pick the right protocol for your domain
    - or design your own
  • - custom JSON format: [event, custom_data]
    - simple standard for client-side events
  • - structured JSON messages allow neat JS client.
    - Browser binds to custom events and manipulates DOM
    - Treat server as any DOM element
  • - Send form to sockets server
    - Familar Javascript events-centric semantics
    - Wrapper sends JSON event convention
  • - Simplified. Trivial
    - wraps WebSocket object
    - callbacks chain
    - JSON encoding - decoding
  • - callback chain
    - add one or more handlers to each event name
  • - hook in WebSocket.onmessage()
    - JSON-decode
    - execute callbacks for each event name
  • Trigger and send event to server
    - JSON-encode message to format convention
    - [event_name, data]

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