Socket#rooms

Socket#rooms:Array A list of strings identifying the rooms this socket is in.

Using multiple nodes

Sticky load balancing If you plan to distribute the load of connections among different processes or machines, you have to make sure that requests associated with a particular session id connect to the process that originated them. This is due to certain transports like XHR Polling or JSONP Polling relying on firing several requests during the lifetime of the “socket”. To illustrate why this is needed, consider the example of emitting an event to all connected clients: io.emit('hi', 'all socket

Socket#join

Socket#join(name:String[, fn:Function]):Socket Adds the socket to the room, and fires optionally a callback fn with err signature (if any). The socket is automatically a member of a room identified with its session id (see Socket#id). The mechanics of joining rooms are handled by the Adapter that has been configured (see Server#adapter above), defaulting to socket.io-adapter.

Socket#to

Socket#to(room:String):Socket

Socket#request

Socket#request:Request A getter proxy that returns the reference to the request that originated the underlying engine.io Client. Useful for accessing request headers such as Cookie or User-Agent.

Socket#leave

Socket#leave(name:String[, fn:Function]):Socket Removes the socket from room, and fires optionally a callback fn with err signature (if any). Rooms are left automatically upon disconnection. The mechanics of leaving rooms are handled by the Adapter that has been configured (see Server#adapter above), defaulting to socket.io-adapter.

Socket#conn

Socket#conn:Socket A reference to the underyling Client transport connection (engine.io Socket object).

Socket

Socket Events connect. Fired upon connecting. error. Fired upon a connection error Parameters: Object error data disconnect. Fired upon a disconnection. reconnect. Fired upon a successful reconnection. Parameters: Number reconnection attempt number reconnect_attempt. Fired upon an attempt to reconnect. reconnecting. Fired upon an attempt to reconnect. Parameters: Number reconnection attempt number reconnect_error. Fired upon a reconnection attempt error. Parameters: Object error o

Socket#emit

Socket#emit(name:String[, …]):Socket Emits an event to the socket identified by the string name. Any other parameters can be included. All datastructures are supported, including Buffer. JavaScript functions can’t be serialized/deserialized. var io = require('socket.io')(); io.on('connection', function(socket){ socket.emit('an event', { some: 'data' }); });

Socket

Socket A Socket is the fundamental class for interacting with browser clients. A Socket belongs to a certain Namespace (by default /) and uses an underlying Client to communicate.