Click to See Complete Forum and Search --> : closing connection
kim24dc
March 12th, 2004, 10:31 AM
I have 2 applications that are connected through TCP. How can I close the connection on the one application so that the other application sees that the connection has been closed? I am currently using closesocket() but the second application doesn't get any indication that this has occured (and keeps on going as if there is a connection).
Thanks
dimm_coder
March 12th, 2004, 10:55 AM
The second application can know about that (the first one called closesocket()) only when it does some operation on that socket (like send()/recv(), ...) or if the second application permanently waits for changing of the state of opened sockets (select(), poll(), etc.). But that depends on the design of your program.
kim24dc
March 12th, 2004, 11:12 AM
The second application has a task that is constantly looking to receive messages from the first applicatins socket using recv(). After I call closesocket() on the first application, the second application is still calling recv() and getting no errors back to say that the first socket is closed. It just keeps on getting bytesread as 0 and an return error of 0. If I completely shutdown the application, then I get the WSAECONNRESET, which is what I need to get(or something similar) when I use closesocket(). Am I supposed to be seeing some kind of error when I try to recv() after the socket is being closed? And if so, since I am not, am I somehow closing it wrong?
dimm_coder
March 12th, 2004, 11:43 AM
The recv() call returns 0 when a connection has been successful closed.
So U get what U must get for that situation.
Check the "return values" section here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/recv_2.asp
kim24dc
March 12th, 2004, 12:23 PM
Thanks! I just completely missed that in the documentation.
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.