Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  63] [ 5]  / answers: 1 / hits: 22260  / 11 Years ago, thu, may 23, 2013, 12:00:00

I am using socket.io and it was quick to setup (thanks to examples on their usage page) but i'd like to find out more about what exactly is going on under covers and what's the technology that makes it work.



what are the exact mechanics of socket.io?



is it on port 80 or a separate one?



does it really stay open or is that part simulated?



is there a way to profile each socket event ?
(sort of like using fiddler to see what happens in ajax calls)


More From » node.js

 Answers
163

For debugging, you might want to try out Theseus.



Here is a short overview of the socket.io SPEC:




Socket.IO aims to bring a WebSocket-like API to many browsers and
devices, with some specific features to help with the creation of
real-world realtime applications and games.




  • Multiple transport support (old user agents, mobile browsers, etc).

  • Multiple sockets under the same connection (namespaces).

  • Disconnection detection through heartbeats.

  • Optional acknoledgments.

  • Reconnection support with buffering (ideal for mobile devices or bad networks)

  • Lightweight protocol that sits on top of HTTP.



Anatomy of a Socket.IO socket



A Socket.IO client first decides on a transport to utilize to connect.



The state of the Socket.IO socket can be disconnected,
disconnecting, connected and connecting.



The transport connection can be closed, closing, open, and
opening.



A simple HTTP handshake takes place at the beginning of a Socket.IO
connection. The handshake, if successful, results in the client
receiving:




  • A session id that will be given for the transport to open connections.

  • A number of seconds within which a heartbeat is expected (heartbeat timeout)

  • A number of seconds after the transport connection is closed when the socket is considered disconnected if the transport connection is
    not reopened (close timeout).



At this point the socket is considered connected, and the transport is
signaled to open the connection.



If the transport connection is closed, both ends are to buffer
messages and then frame them appropriately for them to be sent as a
batch when the connection resumes.



If the connection is not resumed within the negotiated timeout the
socket is considered disconnected. At this point the client might
decide to reconnect the socket, which implies a new handshake.




If you need more of the details, you can read the rest of the specification here


[#78056] Wednesday, May 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;