Socket.io

6,838 views

Published on

Socket.io presentation for Forward 2nd Away day

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,838
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
68
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Socket.io

    1. 1. socket.io in 10 minutes
    2. 2. what it is?• WebSocket-like API• Multiple transport support (old user agents, mobile browsers, etc).• Multiple sockets under the same connection (namespaces).• Disconnection detection through heartbeats.
    3. 3. what it is?• Reconnection support with buffering (ideal for mobile devices or bad networks)• Lightweight protocol that sits on top of HTTP.
    4. 4. socket.io states• disconnected• disconnecting• connected• connecting
    5. 5. transport connection• closed• closing• open• opening
    6. 6. supported transports• xhr-polling• xhr-multipart• htmlfile• websocket• flashsocket• jsonp-polling
    7. 7. code var socket = io.listen(app);var clients = {};socket.on(connection, function(client) { var id = client.sessionId; clients[id] = client; client.on(disconnect, function(){ delete clients[id] })});
    8. 8. code $.each(config.logfile, function(index, log) { tail = spawn(tail, [-n, 1, -f, log]) tail.stdout.on(data, function (data) { $.each(clients, function(index, client) { client.send(json({output: data.toString(), file: log})); }); }) tail.stderr.on(data, function (data) { $.each(clients, function(index, client) { client.send(json({output: data.toString(), file: log})); }); })});
    9. 9. code <script> var socket = new io.Socket(#{"" + hostname + ""}); socket.connect(); socket.on(message, function(data) { log = JSON.parse(data) if (log.file == $(#logfiles).val()){ $(.logs).append(log.output); } });</script>
    10. 10. our maptail fork
    11. 11. server logs
    12. 12. credits• https://github.com/LearnBoost/ socket.io-spec• https://github.com/LearnBoost/ Socket.IO-node-client• https://github.com/stagas/maptail

    ×