@@ -29,6 +29,9 @@ server.bind(41234);
29
29
```
30
30
31
31
## Class: dgram.Socket
32
+ <!-- YAML
33
+ added: v0.1.99
34
+ -->
32
35
33
36
The ` dgram.Socket ` object is an [ ` EventEmitter ` ] [ ] that encapsulates the
34
37
datagram functionality.
@@ -37,23 +40,35 @@ New instances of `dgram.Socket` are created using [`dgram.createSocket()`][].
37
40
The ` new ` keyword is not to be used to create ` dgram.Socket ` instances.
38
41
39
42
### Event: 'close'
43
+ <!-- YAML
44
+ added: v0.1.99
45
+ -->
40
46
41
47
The ` 'close' ` event is emitted after a socket is closed with [ ` close() ` ] [ ] .
42
48
Once triggered, no new ` 'message' ` events will be emitted on this socket.
43
49
44
50
### Event: 'error'
51
+ <!-- YAML
52
+ added: v0.1.99
53
+ -->
45
54
46
55
* ` exception ` {Error}
47
56
48
57
The ` 'error' ` event is emitted whenever any error occurs. The event handler
49
58
function is passed a single Error object.
50
59
51
60
### Event: 'listening'
61
+ <!-- YAML
62
+ added: v0.1.99
63
+ -->
52
64
53
65
The ` 'listening' ` event is emitted whenever a socket begins listening for
54
66
datagram messages. This occurs as soon as UDP sockets are created.
55
67
56
68
### Event: 'message'
69
+ <!-- YAML
70
+ added: v0.1.99
71
+ -->
57
72
58
73
* ` msg ` {Buffer} - The message
59
74
* ` rinfo ` {Object} - Remote address information
@@ -85,12 +100,18 @@ one interface and will add membership to it. To add membership to every
85
100
available interface, call ` addMembership ` multiple times, once per interface.
86
101
87
102
### socket.address()
103
+ <!-- YAML
104
+ added: v0.1.99
105
+ -->
88
106
89
107
Returns an object containing the address information for a socket.
90
108
For UDP sockets, this object will contain ` address ` , ` family ` and ` port `
91
109
properties.
92
110
93
111
### socket.bind([ port] [ , address ] [ , callback] )
112
+ <!-- YAML
113
+ added: v0.1.99
114
+ -->
94
115
95
116
* ` port ` {Number} - Integer, Optional
96
117
* ` address ` {String}, Optional
@@ -139,6 +160,9 @@ server.bind(41234);
139
160
```
140
161
141
162
### socket.bind(options[ , callback] )
163
+ <!-- YAML
164
+ added: v0.11.14
165
+ -->
142
166
143
167
* ` options ` {Object} - Required. Supports the following properties:
144
168
* ` port ` {Number} - Required.
@@ -172,6 +196,9 @@ socket.bind({
172
196
```
173
197
174
198
### socket.close([ callback] )
199
+ <!-- YAML
200
+ added: v0.1.99
201
+ -->
175
202
176
203
Close the underlying socket and stop listening for data on it. If a callback is
177
204
provided, it is added as a listener for the [ ` 'close' ` ] [ ] event.
@@ -193,6 +220,9 @@ If `multicastInterface` is not specified, the operating system will attempt to
193
220
drop membership on all valid interfaces.
194
221
195
222
### socket.send(msg, [ offset, length,] port, address[ , callback] )
223
+ <!-- YAML
224
+ added: v0.1.99
225
+ -->
196
226
197
227
* ` msg ` {Buffer|String|Array} Message to be sent
198
228
* ` offset ` {Number} Integer. Optional. Offset in the buffer where the message starts.
@@ -300,13 +330,19 @@ Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP
300
330
packets may be sent to a local interface's broadcast address.
301
331
302
332
### socket.setMulticastLoopback(flag)
333
+ <!-- YAML
334
+ added: v0.3.8
335
+ -->
303
336
304
337
* ` flag ` {Boolean}
305
338
306
339
Sets or clears the ` IP_MULTICAST_LOOP ` socket option. When set to ` true ` ,
307
340
multicast packets will also be received on the local interface.
308
341
309
342
### socket.setMulticastTTL(ttl)
343
+ <!-- YAML
344
+ added: v0.3.8
345
+ -->
310
346
311
347
* ` ttl ` {Number} Integer
312
348
@@ -320,6 +356,9 @@ The argument passed to to `socket.setMulticastTTL()` is a number of hops
320
356
between 0 and 255. The default on most systems is ` 1 ` but can vary.
321
357
322
358
### socket.setTTL(ttl)
359
+ <!-- YAML
360
+ added: v0.1.101
361
+ -->
323
362
324
363
* ` ttl ` {Number} Integer
325
364
@@ -333,6 +372,9 @@ The argument to `socket.setTTL()` is a number of hops between 1 and 255.
333
372
The default on most systems is 64 but can vary.
334
373
335
374
### socket.ref()
375
+ <!-- YAML
376
+ added: v0.9.1
377
+ -->
336
378
337
379
By default, binding a socket will cause it to block the Node.js process from
338
380
exiting as long as the socket is open. The ` socket.unref() ` method can be used
@@ -346,6 +388,9 @@ The `socket.ref()` method returns a reference to the socket so calls can be
346
388
chained.
347
389
348
390
### socket.unref()
391
+ <!-- YAML
392
+ added: v0.9.1
393
+ -->
349
394
350
395
By default, binding a socket will cause it to block the Node.js process from
351
396
exiting as long as the socket is open. The ` socket.unref() ` method can be used
@@ -383,6 +428,9 @@ s.bind(1234, () => {
383
428
## ` dgram ` module functions
384
429
385
430
### dgram.createSocket(options[ , callback] )
431
+ <!-- YAML
432
+ added: v0.11.13
433
+ -->
386
434
387
435
* ` options ` {Object}
388
436
* ` callback ` {Function} Attached as a listener to ` 'message' ` events.
@@ -405,6 +453,9 @@ and `udp6` sockets). The bound address and port can be retrieved using
405
453
[ ` socket.address().address ` ] [ ] and [ ` socket.address().port ` ] [ ] .
406
454
407
455
### dgram.createSocket(type[ , callback] )
456
+ <!-- YAML
457
+ added: v0.1.99
458
+ -->
408
459
409
460
* ` type ` {String} - Either 'udp4' or 'udp6'
410
461
* ` callback ` {Function} - Attached as a listener to ` 'message' ` events.
0 commit comments