Environment: Windows 7, Visual Studio 2008, C++ MFC
How does class AsyncSocket for the server side detect and notify the application when the client closes the connection?
I wrote the async article found here: Asynchronous TCP Part 1 as a learning tool. Now that I am using that knowledge in a working project I find that when the client closes the socket, I don’t see any results on the server side. I was expecting that OnClose() would be called, but that does not happen. On the client side, after closing, no data can be received until it is Initialized and connected again.
The problem is that in the real application, when the client closes and re-connects the interface protocol for the client requires that the server send some specific information. I am not seeing a way to detect that closure.
Edit: OnClose is declared public. That was an answer in another thread.
And again: I do not have the client code and have no control over the client side behavior.
and again: continued searching yielded something about the read() method getting a result or error. This server application never receives any data from the client and uses no reads. Do I still need to post a read to get a close status?
My application uses C_Server, decended from CAsyncSocket, to post the Listen and call Accept(). In the call to Accept it creates an object from C_Server_Send to communicate with the client. When I add code to post a receive from C_Server_Send, and then close the client, OnClose() from C_Server_Send gets called. So, empirically, I conclude that Yes, I must post a receive to enable detection of client disconnect. Is that correct?
How is C_Server_Send to be deleted.
First: C_Server_Send was newed from C_Server, but that object can create an indefiniate number of C_Server_Send objects as multiple clients connect. Must it keep track of each one.
Second: How does C_Server know that its time to delete an arbitrary instance of C_Server_Send?
Thanks for your time
modified 6-Nov-12 12:54pm.
Last Visit: 31-Dec-99 18:00 Last Update: 28-May-17 16:11