Skip to content

UDP/Datagram Sockets documentation #23952

Description

@dsinecos

Module
UDP/ Datagram Sockets documentation

Current Documentation

The description for the listening event for dgram.Socket states that 'This occurs as soon as UDP sockets are created'. Reference

Expected 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 ...'

Activity

  1. added
    dgramIssues and PRs related to UDP and the dgram module.
    docIssues and PRs related to Node.js documentation.
    on Oct 29, 2018
  2. bnoordhuis commented on Oct 29, 2018

    @bnoordhuis
    Member

    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 
  3. dsinecos commented on Oct 29, 2018

    @dsinecos
    ContributorAuthor

    Thanks @bnoordhuis :)
    This cleared up my confusion.

    Borrowing from your explanation I think the existing description could be modified to something like the following -

    " The listening event is emitted on the first invocation of either send() or bind() for the respective socket.

    While the sockets are addressable immediately after creation using dgram.createSocket NodeJS delays creating the underlying OS socket until the first send() or bind() call is made for the respective socket.

    The listening event is emitted when the underlying OS socket is created (ie on the first invocation of either send() or bind()) "

  4. bnoordhuis commented on Oct 29, 2018

    @bnoordhuis
    Member

    Yes, sounds good. Maybe even cut it short by a few more words. Want to open a PR?

  5. dsinecos commented on Oct 29, 2018

    @dsinecos
    ContributorAuthor

    Yup, I'll edit it and open a PR

    Edit: Submitted a PR here - #23959

  6. tjconcept commented on Apr 14, 2020

    @tjconcept
    Contributor

    I believe this issue should be closed as #32581 landed.

  7. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dgramIssues and PRs related to UDP and the dgram module.docIssues and PRs related to Node.js documentation.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions