Closing Socket Connection!!

Hello,

I have developed a client server application which use TCP sockets for communication. The client application is a MFC windows form using CSocket and the server application is a c++ executable on unix using socket. The problem that I have is on closing the connection. For some reason connection exist after shutdown() and close() from both applications with state FIN_WAIT2 for the client and CLOSE_WAIT for the server. The client closes first. If anyone knows how to clear this connection I'd be thankful.

Thank you!!
Try setting the SO_REUSEADDR socket option.
In theory, CLOSE_WAIT means the sever side has already received 'FIN' from the client, and am waiting for the local side to close the socket.

In server side of you app, which sock you did close? The sock supposed to be closed should be the one from accept().

My server app is working fine without setting SO_REUSEADDR. I met the problem before, but forgot how to fix it.
I have tried the option SO_REUSEADDR and all seems to work properly!!

Thank you jsmith!!
Hi again,

As I saw that the server now can reconnect with the client but the old socket descriptors still exist as opened 'lsof -i:9999'.

b2ee I close the one and only socket after shutdown(sockfd, [0,1,2]).

Topic archived. No new replies allowed.