Repository navigation
UDP/Datagram Sockets documentation #23952
Description
Activity
- addeddgramIssues and PRs related to UDP and the dgram module.Issues and PRs related to UDP and the dgram module.docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Oct 29, 2018 I agree the wording is kind of confusing, even if it's technically correct.
"As UDP sockets are created" refers to the underlying OS socket. They're addressable the moment they're created but Node.js delays creating them until the first send() or bind(). To illustrate:
const dgram = require('dgram') const s = dgram.createSocket('udp4') //console.log(s.address()) // would fail with "getsockname EINVAL", no socket yet s.on('listening', () => console.log(s.address()) s.send('', 12345, () => console.log('done')) // Prints: // { address: '0.0.0.0', family: 'IPv4', port: <random port> } // done
Reacted by Benjamin GruenbaumThanks @bnoordhuis :)
This cleared up my confusion.Borrowing from your explanation I think the existing description could be modified to something like the following -
" The
listeningevent is emitted on the first invocation of eithersend()orbind()for the respective socket.While the sockets are addressable immediately after creation using
dgram.createSocketNodeJS delays creating the underlying OS socket until the firstsend()orbind()call is made for the respective socket.The
listeningevent is emitted when the underlying OS socket is created (ie on the first invocation of eithersend()orbind()) "Yes, sounds good. Maybe even cut it short by a few more words. Want to open a PR?
Yup, I'll edit it and open a PR
Edit: Submitted a PR here - #23959
- added a commit that references this issue
on Nov 29, 2018 I believe this issue should be closed as #32581 landed.
- addedhelp wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.
on Jun 26, 2020
Module
UDP/ Datagram Sockets documentation
Current Documentation
The description for the
listeningevent fordgram.Socketstates that 'This occurs as soon as UDP sockets are created'. ReferenceExpected Documentation
To my understanding this is incorrect as the listening event is fired once the socket is bound to a Port and Address. This is also stated elsewhere in the documentation (Refer) 'Once binding is complete, a 'listening' event is emitted ...'