" is execeted, the application of the chatroom is close auto.
I original idea is stoping listening only not exit the application, when user click the "start listening"
button , it will to relisten. So, there should have some errors i don't know.
Thanks for the good man giving me the answer.

1 solution

Solution 1

"For connection-oriented protocols, it is recommended that you call Shutdown before calling the Close method. This ensures that all data is sent and received on the connected socket before it is closed."

Second thing - it is not clear what you ar doing inside CloseClientSocket.

Third thing - when you perform if (this.listenSocket != null), you should also assign it to null after opeations are finished.

And the last and most important - application closes, probably, because some exception happens during socket.Close method execution. You could try to place it inside try-catch statement and read an error message. Maybe this will help to locate and fix the error.