Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

UDP certainly is connectionless, but that doesn't mean a host can't call `connect` on a UDP scoket. In fact, it is encouraged[1]. I am going to quote the entire paragraph from the RFC, the guidelines document is a very good read if you plan to use UDP.

Succinctly, you should `connect` a UDP socket, it can simplify some calls and allows the application to receive ICMP errors

    Many operating systems also allow a UDP socket to be connected, i.e., to bind a
    UDP socket to a specific pair of addresses and ports.  This is similar to the
    corresponding TCP sockets API functionality.  However, for UDP, this is only a
    local operation that serves to simplify the local send/receive functions and to
    filter the traffic for the specified addresses and ports.  Binding a UDP socket
    does not establish a connection -- UDP does not notify the remote end when a
    local UDP socket is bound.  Binding a socket also allows configuring options
    that affect the UDP or IP layers, for example, use of the UDP checksum or the
    IP Timestamp option.  On some stacks, a bound socket also allows an application
    to be notified when ICMP error messages are received for its transmissions
    [RFC1122].
[1]: https://tools.ietf.org/html/rfc5405#section-3.6


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: