Exports
[<Class>]
type Exports =
static member Socket (?options: EventEmitterOptions) : Socket
static member createSocket (options: SocketOptions, ?callback: Callback2) : Socket
static member createSocket (type: SocketType, ?callback: Callback) : Socket| Assembly | Xantham.Fable.Node |
| Attributes | [<Erase>] |
The package's value exports, each bound to its import.
Methods
static member Socket (?options: EventEmitterOptions) : Socket
static member Socket (?options: EventEmitterOptions) : SocketEncapsulates the datagram functionality.
New instances of dgram.Socket are created using createSocket. The new keyword is not to be used to create dgram.Socket instances.
@since v0.1.99
static member createSocket (options: SocketOptions, ?callback: Callback2) : Socket
static member createSocket (options: SocketOptions, ?callback: Callback2) : SocketCreates a dgram.Socket object. Once the socket is created, calling socket.bind() will instruct the socket to begin listening for datagram messages. When address and port are not passed to socket.bind() the method will bind the socket to the "all interfaces" address on a random port (it does the right thing for both udp4 and udp6 sockets). The bound address and port can be retrieved using socket.address().address and socket.address().port.
If the signal option is enabled, calling .abort() on the corresponding AbortController is similar to calling .close() on the socket:
const controller = new AbortController();
const { signal } = controller;
const server = dgram.createSocket({ type: 'udp4', signal });
server.on('message', (msg, rinfo) => {
console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
});
// Later, when you want to close the server.
controller.abort();
@since v0.11.13
| Parameter | |
|---|---|
options | Available options are: |
callback | Attached as a listener for 'message' events. Optional. |
static member createSocket (type: SocketType, ?callback: Callback) : Socket
static member createSocket (type: SocketType, ?callback: Callback) : SocketCreates a dgram.Socket object. Once the socket is created, calling socket.bind() will instruct the socket to begin listening for datagram messages. When address and port are not passed to socket.bind() the method will bind the socket to the "all interfaces" address on a random port (it does the right thing for both udp4 and udp6 sockets). The bound address and port can be retrieved using socket.address().address and socket.address().port.
If the signal option is enabled, calling .abort() on the corresponding AbortController is similar to calling .close() on the socket:
const controller = new AbortController();
const { signal } = controller;
const server = dgram.createSocket({ type: 'udp4', signal });
server.on('message', (msg, rinfo) => {
console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
});
// Later, when you want to close the server.
controller.abort();
@since v0.11.13
| Parameter | |
|---|---|
options | Available options are: |
callback | Attached as a listener for 'message' events. Optional. |