Constructor
new MessagingSocket(optionsopt)
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Pass options to the constructor. Properties
|
Extends
- EventEmitter
Methods
bind() → {Promise}
Binds the socket and configures datagram handling.
Returns:
- Type
- Promise
close()
Closes the socket, removes all listeners, abandons all Message Supervisors.
discoverSelf(serveropt) → {Array}
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)
Handle an incoming datagram.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
data |
Buffer | Raw datagram data. |
|||||||||
rinfo |
Object | Remote host information. Properties
|
send(data, address, port)
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}
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
Properties:
Name | Type | Description |
---|---|---|
data |
Buffer | Message content. |
ip |
String | Sender ip address. |
port |
Number | Sender port number. |
Full message received.