Server#sockets

Server#sockets:Namespace The default (/) namespace.

Server#adapter

Server#adapter(v:Adapter):Server Sets the adapter v. Defaults to an instance of the Adapter that ships with socket.io which is memory based. See socket.io-adapter. If no arguments are supplied this method returns the current value.

Server

Server Exposed by require('socket.io').

Server#attach

Server#attach(srv:http#Server, opts:Object):Server Attaches the Server to an engine.io instance on srv with the supplied opts (optionally).

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.

Namespace#name

Namespace#name:String The namespace identifier property.

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

Server#bind(srv:engine#Server):Server Advanced use only. Binds the server to a specific engine.io Server (or compatible API) instance.

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

Namespace#connected

Namespace#connected:Object Hash of Socket objects that are connected to this namespace indexed by id.