Re: Losing UDP packets with MFC Sockets



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]
> > >
> > >
>
>
>
.



Relevant Pages

  • Re: Losing UDP packets with MFC Sockets
    ... Vicent Soler wrote: ... 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. ...
    (microsoft.public.vc.mfc)
  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... no concept that allows you to create multipe sockets with the same port number. ... happening is that you are throwing away the old socket and replacing it with the new ... That is not the same as creating multiple sockets with the same port #. ... Because I will send real-time video frame, I use UDP socket. ...
    (microsoft.public.vc.mfc)
  • Re: Howto find multiple servers using TCP
    ... You will have to create a UDP socket ... When a packet is sent using a UDP socket ... differences between multicast and regular udp packets, ... But if the server program is your program, ...
    (microsoft.public.vc.mfc)
  • Re: Looking for information on MFC TCP Communication
    ... > Note that to use the MFC socket classes the separate threads must be UI threads, ... > there is rarely a need to use separate threads. ... > objects, and not touching the GUI, there are no "thread issues". ... allocate the buffer, but this may be allocating / deleting alot of ...
    (microsoft.public.vc.mfc)
  • Re: tcp connection in gui: event based
    ... Write a small proc that does the accept and sets the connection to ... Use to register procs that get fired when the socket is ... If you have a full line, send it to the GUI, maybe dispatching via ... after to not block the event loop if its a bit bigger ...
    (comp.lang.tcl)