-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UDP/Datagram Sockets documentation #23952
Comments
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 |
Thanks @bnoordhuis :) Borrowing from your explanation I think the existing description could be modified to something like the following - " The While the sockets are addressable immediately after creation using The |
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 |
Clarify that the `'listening'` event is emitted when the underlying OS socket is created This occurs when either `socket.send()` or `socket.bind()` are first invoked for the respective socket. Fixes: nodejs#23952
I believe this issue should be closed as #32581 landed. |
Module
UDP/ Datagram Sockets documentation
Current Documentation
The description for the
listening
event fordgram.Socket
states 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 ...'
The text was updated successfully, but these errors were encountered: