Do I have to bind a UDP socket in my client program to receive data? (I always get WSAEINVAL)

前端 未结 4 1533
挽巷
挽巷 2020-12-02 18:27

I am creating a UDP socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) via Winsock and trying to recvfrom on this socket, but it a

4条回答
  •  醉话见心
    2020-12-02 19:19

    Here it says the following:

    Parameters

    s [in]: A descriptor identifying a bound socket.

    ...

    Return Value

    WSAEINVAL: The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled, or (for byte stream-style sockets only) len was zero or negative.

    As far as I remember bind is not required for a UDP socket because a bind call is made for you by the stack. I guess it's a Windows thing to require a bind on a socket used in a recvfrom call.

提交回复
热议问题