@@ -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(buf, offset, length, port, address[ , callback] )
223
+ <!-- YAML
224
+ added: v0.1.99
225
+ -->
196
226
197
227
* ` buf ` {Buffer|String} Message to be sent
198
228
* ` offset ` {Number} Integer. Offset in the buffer where the message starts.
@@ -277,13 +307,19 @@ Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP
277
307
packets may be sent to a local interface's broadcast address.
278
308
279
309
### socket.setMulticastLoopback(flag)
310
+ <!-- YAML
311
+ added: v0.3.8
312
+ -->
280
313
281
314
* ` flag ` {Boolean}
282
315
283
316
Sets or clears the ` IP_MULTICAST_LOOP ` socket option. When set to ` true ` ,
284
317
multicast packets will also be received on the local interface.
285
318
286
319
### socket.setMulticastTTL(ttl)
320
+ <!-- YAML
321
+ added: v0.3.8
322
+ -->
287
323
288
324
* ` ttl ` {Number} Integer
289
325
@@ -297,6 +333,9 @@ The argument passed to to `socket.setMulticastTTL()` is a number of hops
297
333
between 0 and 255. The default on most systems is ` 1 ` but can vary.
298
334
299
335
### socket.setTTL(ttl)
336
+ <!-- YAML
337
+ added: v0.1.101
338
+ -->
300
339
301
340
* ` ttl ` {Number} Integer
302
341
@@ -310,6 +349,9 @@ The argument to `socket.setTTL()` is a number of hops between 1 and 255.
310
349
The default on most systems is 64 but can vary.
311
350
312
351
### socket.ref()
352
+ <!-- YAML
353
+ added: v0.9.1
354
+ -->
313
355
314
356
By default, binding a socket will cause it to block the Node.js process from
315
357
exiting as long as the socket is open. The ` socket.unref() ` method can be used
@@ -323,6 +365,9 @@ The `socket.ref()` method returns a reference to the socket so calls can be
323
365
chained.
324
366
325
367
### socket.unref()
368
+ <!-- YAML
369
+ added: v0.9.1
370
+ -->
326
371
327
372
By default, binding a socket will cause it to block the Node.js process from
328
373
exiting as long as the socket is open. The ` socket.unref() ` method can be used
@@ -360,6 +405,9 @@ s.bind(1234, () => {
360
405
## ` dgram ` module functions
361
406
362
407
### dgram.createSocket(options[ , callback] )
408
+ <!-- YAML
409
+ added: v0.11.13
410
+ -->
363
411
364
412
* ` options ` {Object}
365
413
* ` callback ` {Function} Attached as a listener to ` 'message' ` events.
@@ -382,6 +430,9 @@ and `udp6` sockets). The bound address and port can be retrieved using
382
430
[ ` socket.address().address ` ] [ ] and [ ` socket.address().port ` ] [ ] .
383
431
384
432
### dgram.createSocket(type[ , callback] )
433
+ <!-- YAML
434
+ added: v0.1.99
435
+ -->
385
436
386
437
* ` type ` {String} - Either 'udp4' or 'udp6'
387
438
* ` callback ` {Function} - Attached as a listener to ` 'message' ` events.
0 commit comments