doc: Add callback parameter to dgram socket.bind()
Also, describe more details of bind().
This commit is contained in:
parent
2385fbbc3a
commit
9456cf8fe2
@ -127,13 +127,21 @@ informing the source that the data did not reach its intended recipient).
|
|||||||
|
|
||||||
* `port` Integer
|
* `port` Integer
|
||||||
* `address` String, Optional
|
* `address` String, Optional
|
||||||
* `callback` Function, Optional
|
* `callback` Function with no parameters, Optional. Callback when
|
||||||
|
binding is done.
|
||||||
|
|
||||||
For UDP sockets, listen for datagrams on a named `port` and optional `address`.
|
For UDP sockets, listen for datagrams on a named `port` and optional
|
||||||
If `address` is not specified, the OS will try to listen on all addresses.
|
`address`. If `address` is not specified, the OS will try to listen on
|
||||||
|
all addresses. After binding is done, an "listening" event is emitted
|
||||||
|
and the `callback`(if specified) is called. Specifying both an
|
||||||
|
"listening" event listener and `callback` is not harmful but not very
|
||||||
|
useful.
|
||||||
|
|
||||||
The `callback` argument, if provided, is added as a one-shot `'listening'`
|
A bound datagram socket keeps the node process running to receive
|
||||||
event listener.
|
datagrams.
|
||||||
|
|
||||||
|
If binding fails, an "error" event is generated. In rare case (e.g.
|
||||||
|
binding a closed socket), an `Error` may be thrown by this method.
|
||||||
|
|
||||||
Example of a UDP server listening on port 41234:
|
Example of a UDP server listening on port 41234:
|
||||||
|
|
||||||
@ -141,6 +149,11 @@ Example of a UDP server listening on port 41234:
|
|||||||
|
|
||||||
var server = dgram.createSocket("udp4");
|
var server = dgram.createSocket("udp4");
|
||||||
|
|
||||||
|
server.on("error", function (err) {
|
||||||
|
console.log("server error:\n" + err.stack);
|
||||||
|
server.close();
|
||||||
|
});
|
||||||
|
|
||||||
server.on("message", function (msg, rinfo) {
|
server.on("message", function (msg, rinfo) {
|
||||||
console.log("server got: " + msg + " from " +
|
console.log("server got: " + msg + " from " +
|
||||||
rinfo.address + ":" + rinfo.port);
|
rinfo.address + ":" + rinfo.port);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user