Timeless - Websocket on Rails

776 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
776
On SlideShare
0
From Embeds
0
Number of Embeds
41
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Timeless - Websocket on Rails

  1. 1. Ruby on Rails & WebSocket Le Hoai Phuong Nguyen Huy Hung Hoang Van Quan Cao Duy Khanh Vu Van Chuyen Timeless
  2. 2. ● WebSocket Overview ● Benefit ● How does WS work? ● Pros & Cons ● WebSocket on Rails ● Summary Content
  3. 3. WebSocket Overview ● Full-duplex channels over a single TCP connection ● Was standardized in 2011 ● Use an HTTP Upgrade request for handshaking
  4. 4. Upgrade Request GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 Origin: http://example.com HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat Client Request Server Response
  5. 5. WebSocket Benefit ● Overhead of HTTP ○ 1 HTTP request/response Header: 871 bytes ○ 1 WS frame: 2 bytes ● Low Latency
  6. 6. How does it work?
  7. 7. Pros & Cons ● Pros ○ Realtime ○ Lightweight ○ Low latency ○ Full duplex ● Cons ○ Still in working progress ○ Not suitable for streaming large data (HD video) ○ Hard to control multi-channels
  8. 8. WebSocket on Rails ● Web server ○ Event Based ○ or Client WS simulation using JavaScript ● Many gems: websocket-rails, em-websocket, evma_httpserver
  9. 9. Reactor pattern Request EventMachine (demultiplexer - dispatcher) Thin (Web Server) Rack Rails adapter Rack Thin handler Rails
  10. 10. A demo coding with gem websocket-rails
  11. 11. Summary ● Realtime ● New ● Lightweight ● Full duplex

×