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#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.

Logging and Debugging

Socket.IO is now completely instrumented by a minimalistic yet tremendously powerful utility called debug by TJ Holowaychuk. Before 1.0, the Socket.IO server would default to logging everything out to the console. This turned out to be annoyingly verbose for many users (although extremely useful for others), so now we default to being completely silent by default. The basic idea is that each module used by Socket.IO provides different debugging scopes that give you insight into the internals. B

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

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.

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.

Migration from 0.9

For most applications, the transition to 1.0 should be completely seamless and devoid of any hiccups. That said, we’ve done some work to streamline some APIs, and we have changed some internals, so this is a recommended read for most existing users. Authentication differences Socket.io uses middleware now You can give a Socket.io server arbitrary functions via io.use() that are run when a socket is created. Check out this example: var srv = require('http').createServer(); var io = require('sock

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

Manager#reconnectionDelay

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

Namespaces

Socket.IO allows you to “namespace” your sockets, which essentially means assigning different endpoints or paths. This is a useful feature to minimize the number of resources (TCP connections) and at the same time separate concerns within your application by introducing separation between communication channels. Default namespace We call the default namespace / and it’s the one Socket.IO clients connect to by default, and the one the server listens to by default. This namespace is identified by