UDP Sockets in C

后端 未结 4 1101

I\'m working on a homework problem for class. I want to start a UDP Server that listens for a file request. It opens the file and sends it back to the requesting client with

4条回答
  •  旧巷少年郎
    2021-01-05 23:59

    How UDP is different from TCP:

    • message-oriented, not stream-oriented. You don't read/write or send/recv. You sendto/recvfrom. The size of message is limited to 64K. Each call to recvfrom gets one message sent by a call to sendto. If recvfrom passes a buffer that's smaller than the size of message, the rest of message is gone for good.

    • no connections. Therefore no listen/accept/connect. You send a message to a particular address/port. When you receive message (on the address/port to which your socket is bound), you get the source of the incoming message as an output parameter to recvfrom.

    • no guarantees. The messages can be dropped or received out of order. If I remember correctly, they cannot be truncated, though.

    One last word of caution - you may find yourself re-inventing TCP over UDP. In that case, stop and go back to TCP.

提交回复
热议问题