File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,26 @@ Tells the kernel to join a multicast group at the given `multicastAddress` and
95
95
one interface and will add membership to it. To add membership to every
96
96
available interface, call ` addMembership ` multiple times, once per interface.
97
97
98
+ UDP works as a bit special with cluster. When ` dgram ` creates a socket in the
99
+ master process, each worker gets a copy as in `dup(2)``, except the actual
100
+ mechanism is ` sendmsg(2)`` with a SCM_RIGHTS vector. Therefor, ` .addMembership`
101
+ needs to be managed to be called only once.
102
+
103
+ ``` js
104
+ const cluster = require (' cluster' );
105
+ const dgram = require (' dgram' );
106
+
107
+ if (cluster .isMaster ) {
108
+ cluster .fork (); // ok
109
+ cluster .fork (); // EADDRINUSE
110
+ } else {
111
+ const s = dgram .createSocket (' udp4' );
112
+ s .bind (1234 , () => {
113
+ s .addMembership (' 224.0.0.114' );
114
+ });
115
+ }
116
+ ```
117
+
98
118
### socket.address()
99
119
<!-- YAML
100
120
added: v0.1.99
You can’t perform that action at this time.
0 commit comments