Your SlideShare is downloading. ×
Socket.io under the hood
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Socket.io under the hood

482
views

Published on

Socket.io communication in detail

Socket.io communication in detail

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
482
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
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

Transcript

  • 1. Hao-kang Den @_hden Socket.io under the hood
  • 2. Agenda ● Why socket.io? ● What’s socket.io? What’s websocket? ● Socket.io in detail
  • 3. HTTP serverclient (1) request (2) response WTF? X
  • 4. Bi-directional Communication serverclient (1) signal (2) acknowledgement (3) signal (4) acknowledgement
  • 5. Why don’t we use websocket? ● Standardized by ○ RFC 6455 ○ W3C ● IE9 says NO
  • 6. Why socket.io? + native iOS & Android
  • 7. Socket.io Communication Layers API packet communication (ws, jsonp, etc.)
  • 8. API # client socket.emit(‘foo’, param1, param2, ...) socket.on ‘bar’, (param1, param2, ...) -> console.log(‘yay got a bar!’) # server socket.on ‘foo’, (param1, param2, ...) -> console.log(‘yay got a foo!’) socket.emit(‘bar’, param1, param2, ...)
  • 9. Packet socket.emit(‘foo’, param1, param2, ...) # socket.io v0.9.x packet = { type: ‘event’ id: ‘unique packet id’ name: ‘foo’ args: [param1, param2, ...] } # socket.io v1.0.x packet = { type: ‘event’ id: ‘unique packet id’ name: ‘foo’ data: [param1, param2, ...] } https://github.com/LearnBoost/socket.io-protocol
  • 10. Communication Layer # socket.io v0.9.x packet = { type: ‘event’ id: 1 name: ‘foo’ args: [param1, param2, ...] } # socket.io v0.9.x 5:1::{“name”:”foo”,”args”:[param1, param2, ...]} https://github.com/LearnBoost/socket.io-spec
  • 11. Further Reading ● http://davidwalsh.name/websocket ● test/spec https://github.com/LearnBoost/socket.io/blob/master/test/socket.io.js ● code https://github.com/LearnBoost/socket.io/blob/master/lib/socket.js read!