Manager#reconnectionAttempts

Manager#reconnectionAttempts(v:Boolean):Manager Sets the reconnectionAttempts option, or returns it if no parameters are passed.

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

Server#emit

Server#emit Emits an event to all connected clients. The following two are equivalent: var io = require('socket.io')(); io.sockets.emit('an event sent to all connected clients'); io.emit('an event sent to all connected clients'); For other available methods, see Namespace below.

Server#serveClient

Server#serveClient(v:Boolean):Server If v is true the attached server (see Server#attach) will serve the client files. Defaults to true. This method has no effect after attach is called. // pass a server and the `serveClient` option var io = require('socket.io')(http, { serveClient: false }); // or pass no server and then you can call the method var io = require('socket.io')(); io.serveClient(false); io.attach(http); If no arguments are supplied this method returns the current value.

Socket#in

Socket#in(room:String):Socket Sets a modifier for a subsequent event emission that the event will only be broadcasted to sockets that have joined the given room. To emit to multiple rooms, you can call to several times. var io = require('socket.io')(); io.on('connection', function(socket){ socket.to('others').emit('an event', { some: 'data' }); });

Manager#reconnectionDelayMax

Manager#reconnectionDelayMax(v:Boolean):Manager Sets the reconectionDelayMax option, or returns it if no parameters are passed.

Namespace#use

Namespace#use(fn:Function):Namespace Registers a middleware, which is a function that gets executed for every incoming Socket and receives as parameter the socket and a function to optionally defer execution to the next registered middleware. var io = require('socket.io')(); io.use(function(socket, next){ if (socket.request.headers.cookie) return next(); next(new Error('Authentication error')); }); Errors passed to middleware callbacks are sent as special error packets to clients.

IO

IO(url:String, opts:Object):Socket Exposed as the io global in window if using the standalone build (eg: /socket.io/socket.io.js or the CDN), or the result of calling require('socket.io-client'). When called, it creates a new Manager for the given URL, and attempts to reuse an existing Manager for subsequent calls, unless the multiplex option is passed with false. Passing this option is the equivalent of passing 'force new connection': true. The rest of the options are passed to the Manager con

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.

Manager

Manager(url:String, opts:Object) A Manager represents a connection to a given Socket.IO server. One or more Socket instances are associated with the manager. The manager can be accessed through the io property of each Socket instance. The opts are also passed to engine.io upon initialization of the underlying Socket. Options: – reconnection whether to reconnect automatically (true) – reconnectionDelay how long to wait before attempting a new reconnection (1000) – reconnectionDelayMax maximum am