Re: Losing UDP packets with MFC Sockets



Vicent Soler wrote:
I'm not sure about your thread solution:

- Are you saying that I sould derive my class from both CAsyncSocket and CWinThread?? With this king of inheritage, the OnReceive notification will be implemented in specific thread different from the main thread, right? If I want to access the derived class from the main thread, could exist any conflict? Should I use Critical Section in every method of the class? Please, let me know any sample, if possible...

Thanks, I hope it works...

Vicent

I'm not saying use multiple inheritance. I'm saying, if you want to use a thread, you must use the kind that is derived from CWinThread. Put your socket into your thread as a member variable. Call the socket only from the thread. If you put the socket in such a thread you cannot access it or use it from the main thread.


What you can do is copy the received data to the heap and pass the heap pointer to the main thread using PostMessage to the main window.

--
Scott McPhillips [VC++ MVP]

.



Relevant Pages

  • Re: CAsyncSocket in a DLL, frequent crashes on close in DetachHandle
    ... regular thread for 'listening' (not CWinThread). ... doesn't have a message pump, so my socket was disfunctional - receiving ... To further investigate the NULL window handle you could try and check if the window is even created in the first place. ... perhaps it is destroyed before you get around to closing the socket. ...
    (microsoft.public.vc.mfc)
  • Re: UI Thread and CSocket
    ... The message pump definitely does not run when a UI thread is ... > MFC multithread socket example code? ... This is an CSocket object, ... Within that CWinThread object, there is an instance of the CSocket. ...
    (microsoft.public.vc.mfc)
  • Re: newbie question about threads and sockets...
    ... > i want to have a thread waiting for message (user message) and also in that ... > However I couldnt create a socket.. ... > they have written accept method after listen method but ... the message pump that is built in to CWinThread instead of using your own. ...
    (microsoft.public.vc.mfc)