Socket

Socket

Object for sending and receiving messages the raw WebSocket. It is not recommended to use this object in your code, as it is used internally.

Accessable from a Server object via Server.socket.

Constructor

new Socket(server, host)

Source:
Properties:
Name Type Description
host string

The host WebSocket address. Example: ws://localhost:5050

connected bool

Will be true if the server is connected to the WebSocket, and false otherwise.

server object

The Server object this belongs to.

ws object

The WebSocket class provided by the ws module. Used for actually sending and receiving messages.

acknowledgements array

List of acknowledgements received from the server. Used to recognize when the server successfully processes a message.

Parameters:
Name Type Description
server Server

The Server object this belongs to.

host string

Websocket address. Example: ws://localhost:5050

Methods

disconnect()

Source:

Disconnects from the WebSocket.

send(type, message)

Source:

Sends a raw message to the WebSocket

Parameters:
Name Type Description
type string
message object

Events

disconnect

Source:

Fired when the WebSocket disconnects.

error

Source:

Used internally for when the WebSocket experiences an error.

Parameters:
Name Type Description
error Error

The error that occured.

event

Source:

Used internally for when a raw event is received from the server. It isn't recommended to use this event in your code.

Parameters:
Name Type Description
json object

The message data sent by the server.

raw

Source:

Fired when a WebSocket packet is received.

Parameters:
Name Type Description
data Buffer

Raw data sent by the server.

ready

Source:

Fired when the connection to the server has been established.