Skip to content
ethagnawl edited this page Apr 12, 2012 · 7 revisions

Server

On the server, assuming var io = require('socket.io'),

  • io.sockets.on('connection', function(socket) {}) - initial connection from a client. socket argument should be used in further communication with the client.
  • socket.on('message', function(message, callback) {}) - "message" is emitted when a message sent with socket.send is received. message is the message sent, and callback is an optional acknowledgement function.
  • socket.on('anything', function(data) {}) - "anything" can be any event except for the reserved ones.
  • socket.on('disconnect', function() {}) - fired when the socket disconnects? Not sure when exactly, i.e. will it only fire if client initiates disconnect or also if server initiates disconnect. Does it fire on unexpected network failure, or a mobile device losing connection?

Client

The client doc (including event list) is available here: https://github.com/LearnBoost/socket.io-client

On the client, assuming var socket = io.connect(host, options),

  • socket.on('connect', function () {}) - "connect" is emitted when the socket connected successfully
  • socket.on('connecting', function () {}) - "connecting" is emitted when the socket is attempting to connect with the server.
  • socket.on('disconnect', function () {}) - "disconnect" is emitted when the socket disconnected
  • socket.on('connect_failed', function () {}) - "connect_failed" is emitted when socket.io fails to establish a connection to the server and has no more transports to fallback to.
  • socket.on('error', function () {}) - "error" is emitted when an error occurs and it cannot be handled by the other event types.
  • socket.on('message', function (message, callback) {}) - "message" is emitted when a message sent which socket.send is received. message is the sent message, and callback is an optional acknowledgement function.
  • socket.on('anything', function(data, callback) {}) - "anything" can be any event except for the reserved ones. data is data, and callback can be used to send a reply.
  • socket.on('reconnect_failed', function () {}) - "reconnect_failed" is emitted when socket.io fails to re-establish a working connection after the connection was dropped.
  • socket.on('reconnect', function () {}) - "reconnect" is emitted when socket.io successfully reconnected to the server.
  • socket.on('reconnecting', function () {}) - "reconnecting" is emitted when the socket is attempting to reconnect with the server.

Clone this wiki locally