Search code examples
csocketstcpexitcontrol-c

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


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 use "control-c" to close the sending process? shouldn't the socket on the sending peer be closed after "control-c" to exit the process? Thanks!


Solution

  • 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.