why socket on the receiving peer keep receiving '' infinitely when I use “control-c” to close the socket on the sending peer

前端 未结 2 1371
暖寄归人
暖寄归人 2021-01-29 14:24

I\'m a newbie to socket programming, I know it\'s a bad habit to close socket using \"control-c\", but why socket on the receiving peer keeps receiving \'\' infinitely after I u

2条回答
  •  走了就别回头了
    2021-01-29 15:02

    I know it's a bad habit to close socket using "control-c"

    That closes the entire process, not just a socket.

    why socket on the receiving peer keeps receiving '' infinitely after I use "control-c" to close the sending process?

    At a guess, which is all that is possible without seeing the code you should have posted in your question, you are ignoring errors and end-of-stream when calling recv().

    shouldn't the socket on the sending peer be closed after "control-c" to exit the process?

    It is. The whole process is 'closed', including all its resources.

    As regards the receiving socket, it is up to you to detect the conditions under which it should be close, and close it.

提交回复
热议问题