CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Nov 2011
    Posts
    72

    CAsyncSocket close problem

    Environment: windows XP and Win 7, Visual Studio 2008, MFC, C++, CAsyncSocket

    Setup: I wrote a test program that drives the server side and the client side of a TCP/IP connection using CAsyncSocket. It uses a C_Server class to listen for the client and accept the connection. That class creates an instance of the C_Server_Send object to send data to the client. It is working but is missing the proper closing function. I am working on fixing that. Now when the client closes the socket the C_Server_Send OnClose() is called. But I don’t know what to do here. The CAsyncSocket::Close does not appear to cause the object to delete itself. C_Server does not know that OnClose() has been called so the object that created this cannot delete it.

    Question:
    When the client closes the connection, what is the proper method to delete object CAsyncSocket?

    Question:
    In all the On*() overridden methods, should I load them up with error checking such as WSAGetLastError()?

    Note: If interested, I wrote up an article on this and posted it on codeproject.com here:
    http://www.codeproject.com/Articles/...84#xx4382684xx
    I have since realized that while it ends with error code zero, it still does not have proper closing code. That work is in progress. I discovered this as I started implementing my code in a real world application.
    Last edited by bkelly; November 6th, 2012 at 09:42 PM. Reason: typos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured