MessagingSocket

MessagingSocket

A socket that handles receiving and sending messages.

Constructor

new MessagingSocket(optionsopt)

Source:
Parameters:
Name Type Attributes Description
options Object <optional>

Pass options to the constructor.

Properties
Name Type Attributes Default Description
ip String <optional>
0.0.0.0

IP address to bind to.

port Number <optional>
0

Port number to bind to. Defaults to 0 (random free port).

socket Object <optional>
null

Use an existing socket. If null then creates a new udp4 socket.

MTU Number <optional>
1400

Use a different MTU value. Messages longer than MTU are divided into subpackets.

Extends

  • EventEmitter

Methods

bind() → {Promise}

Source:

Binds the socket and configures datagram handling.

Returns:
Type
Promise

close()

Source:

Closes the socket, removes all listeners, abandons all Message Supervisors.

discoverSelf(serveropt) → {Array}

Source:

Perform a STUN request.

Parameters:
Name Type Attributes Description
server String <optional>

The STUN server to use.

Returns:

An array containing [ip, port]

Type
Array

handleDatagram(data, rinfo)

Source:

Handle an incoming datagram.

Parameters:
Name Type Description
data Buffer

Raw datagram data.

rinfo Object

Remote host information.

Properties
Name Type Description
address String

Remote host ip address.

port Number

Remote host port number.

send(data, address, port)

Source:

Send a raw datagram to a remote host.

Parameters:
Name Type Description
data Buffer

The datagram data.

address String

Target host ip address.

port Number

Target host port number.

sendMessage(data, ip, port) → {Promise}

Source:

Send a message to a remote host. The remote host must also use this library to receive and understand the data.

Parameters:
Name Type Description
data Buffer

The message contents.

ip String

Remote host ip address.

port Number

Remote host port number.

Returns:

Message delivery promise. Resolves when a message is fully received or the socket is closed. Rejects if the remote end did not respond.

Type
Promise

Events

message

Source:
Properties:
Name Type Description
data Buffer

Message content.

ip String

Sender ip address.

port Number

Sender port number.

Full message received.