CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2000
    Location
    Uzbekistan
    Posts
    92

    How to work with CAsyncSocket in multitasking environment?

    I'v created CAsyncSocket object and connected it in main thread. I started "watchdog" thread and in the case of broken connection i want to reconnect. All operations in "watchdog" result in unhandled exception, but the object is correct. May be threre is some rule in working with CAsyncSocket object from other thread?

    Thanks

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    This is about the 50th time that this question has come up in the last month so once again.....

    You can't pass most objects derived from CObject around between threads. You'll have to do some kind of message passing instead.

    You certainly can't do CWnd and derived classes and I bet you can't do CAsyncSocket either.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    However, you can create your own sockets using WinSock and pass their handles around between threads which is what I always do.

    CAsyncSocket (again for the 50th time) is a bit rubbish to be honest and isn't reliable at all.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]

  5. #5
    Join Date
    Jul 2001
    Location
    Viet Nam
    Posts
    132
    If socket S was created by thread A, then the socket S must also be closed by thread A. It would crashed it thread B trying to close S.

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