recv() socket function returning data with length as 0

后端 未结 8 2073
甜味超标
甜味超标 2020-12-24 07:55

I am having an application which established a socket connection on a port number 5005 with another device(hardware device with a web server).

Now if my hardware de

8条回答
  •  遥遥无期
    2020-12-24 08:28

    Given that you're talking to a web server, I'll assume you're using TCP sockets.

    To answer:

    1. Sockets don't become invalid due to a disconnect; they simply go into a disconnected state. It's still safe to call socket operations on them.

    2. You don't get any special messages when the disconnect occurs. If you call recv() in a blocking fashion, it will return when disconnected, and the number of bytes returned from the call won't match the number of bytes you asked for.

    3. There isn't really an answer to this - it's how the socket API was implemented originally, and we're stuck with that implementation as everyone implements Berkley Sockets.

提交回复
热议问题