Re: Losing UDP packets with MFC Sockets
- From: Vicent Soler <VicentSoler@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 15 Apr 2005 08:46:01 -0700
Hi AliR,
I think that this kind of implementation have a problem in my code:
1.- I'm using OLE Automation with two applications: the engine is written in
VC++ and the GUI in VB.
2.- The UDP socket is not always open and depend on the working mode of the
GUI. It means that the UDP socket can be open or closed many times during the
application's life.
3.- To open/close the UDP socket the GUI calls a method from the Engine to
proceed and then the engine processes the call and opens/closes the UDP
socket. So, as you can imagine, I need a unique thread to manage UDP sockets
because the GUI is waiting for the response. While the Engine is processing
the call, the GUI is block waiting for the response and if after that the
response is valid, the GUI continues with the operations.
4.- And another problem, how can I kill the thread from the main application
once it is running.
Mmmmm.... Maybe I'm wrong but I don't see the solution you are defending.
I'll try to investigate more...
Vicent
"AliR" wrote:
> You end the thread which will close the socket in it's ExitInstance, or
> simply post a message to tell it to close.
>
> AliR.
>
> "Vicent Soler" <VicentSoler@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:AB7DB57B-D436-41E6-B7DD-B10CC2033C08@xxxxxxxxxxxxxxxx
> > OK, I understand now. But with this implementation, I see a problem: how
> can
> > I close the socket from the main thread? Should I use Windows messaging?
> >
> > Vicent
> >
> > "Scott McPhillips [MVP]" wrote:
> >
> > > 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]
> > >
> > >
>
>
>
.
- Follow-Ups:
- Re: Losing UDP packets with MFC Sockets
- From: Scott McPhillips [MVP]
- Re: Losing UDP packets with MFC Sockets
- References:
- Losing UDP packets with MFC Sockets
- From: Vicent Soler
- Re: Losing UDP packets with MFC Sockets
- From: Scott McPhillips [MVP]
- Re: Losing UDP packets with MFC Sockets
- From: Vicent Soler
- Re: Losing UDP packets with MFC Sockets
- From: Scott McPhillips [MVP]
- Re: Losing UDP packets with MFC Sockets
- From: Vicent Soler
- Re: Losing UDP packets with MFC Sockets
- From: Scott McPhillips [MVP]
- Re: Losing UDP packets with MFC Sockets
- From: Vicent Soler
- Re: Losing UDP packets with MFC Sockets
- From: AliR
- Losing UDP packets with MFC Sockets
- Prev by Date: Re: Difference between CRegKey::QueryStringValue and RegQueryValueEx
- Next by Date: COleDateTime ,SystemTimeToVariantTime Issues Questions
- Previous by thread: Re: Losing UDP packets with MFC Sockets
- Next by thread: Re: Losing UDP packets with MFC Sockets
- Index(es):
Relevant Pages
|