Class: Server

Server

new Server(optsopt)

The server class.
Parameters:
Name Type Attributes Description
opts Object <optional>
The Server and net.Server options.
Properties
Name Type Attributes Default Description
objectSerializer function <optional>
JSON.stringify Serializes an object into a binary buffer. This functions allows you to implement custom serialization protocols for the data or even use other known protocols like "Protocol Buffers" or "MessagePack".
objectDeserializer function <optional>
JSON.parse Deserializes a binary buffer into an object. This functions allows you to implement custom serialization protocols for the data or even use other known protocols like "Protocol Buffers" or "MessagePack".
Source:
Fires:

Members

rooms :Object

The rooms with at least one socket or more. The key is the room name and the value an array of sockets.
Type:
  • Object
Source:

sockets :Object

The connected sockets. The key is the Socket.id and the value a Socket instance.
Type:
  • Object
Source:

Methods

close()

Disconnect all the clients and close the server.
Source:

emit(event, data, optsopt)

Emit an event, if no sockets or rooms are provided, the event will be broadcasted to all connected sockets.
Parameters:
Name Type Attributes Description
event String The event name.
data String | Number | Object | Buffer | Boolean The data to send.
opts Object <optional>
The options.
Properties
Name Type Attributes Default Description
sockets Array.<String> <optional>
[] The list of socket ids to send.
rooms Array.<String> <optional>
[] The list of rooms to send.
except Array.<String> <optional>
[] The list of socket ids to exclude.
Source:

join(room, socketId)

Join to a room.
Parameters:
Name Type Description
room String The room name.
socketId String The socket id.
Source:

leave(room, socketId)

Leave a room.
Parameters:
Name Type Description
room String The room name.
socketId String The socket id.
Source:

leaveAll(socketId)

Leave all rooms.
Parameters:
Name Type Description
socketId String The socket id.
Source:

listen(portopt)

Start the server. It calls the underline net.Server#listen with the given arguments so multiple optional arguments can be used.
Parameters:
Name Type Attributes Description
port Number <optional>
The port to listen to, this is the most basic usage, check the link for more advanced usages.
Source:
See:

stream(event, data, optsopt)

Creates and returns a stream.Writable instance that can be used to stream binary data. If no opts.sockets or opts.rooms are provided, the stream will be broadcasted to all connected sockets.
Parameters:
Name Type Attributes Description
event String The event name.
data String | Number | Object | Buffer | Boolean The data to send.
opts Object <optional>
The options.
Properties
Name Type Attributes Default Description
sockets Array.<String> <optional>
[] The list of socket ids to send.
rooms Array.<String> <optional>
[] The list of rooms to send.
except Array.<String> <optional>
[] The list of socket ids to exclude.
Source:

Events

close

Close event from net.Server.
Source:

connection

A new Socket was connected.
Source:

error

Error event from net.Server.
Source:

listening

Listening event from net.Server.
Source: