Re: CSocket, best way to wait for a reply?



You better use CAsyncSocket. And wait for OnRecieve
avoid sleeping of a ui thread
rather use AtlWaitWithMessageLoop on a waitable timer
"simon" <spambucket@xxxxxxxxxxxx> wrote in message
news:%23BVWnAuOFHA.3408@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I have a 'client' and a 'server', (both the same sub-classes of CSocket).
> Basically the client sends a message to the server and in turn the server
> sends a message back to the client.
> I allow a few seconds for the server to reply back to the client. Ideally
it
> should not take more than a few milliseconds.
> The client waits for it's reply, (recognized by a special header in the
> message).
>
> So what I have is a function that does something like...
>
> void MyMessage( void *pData, int nSize )
> {
> pMySocket->Send( pData, nSize );
>
> // wait for a reply from the server
> while( pMySocket->pReplyBuffer == NULL ){
> sleep(0); // give time back to the queue
> // wait for a few seconds only
> }
>
> // either timeout or no reply sent
> }
>
> // The server then receives the message sent
> // sends a reply back to the client
> // who in turn fills the void *pReplyBuffer
> //
> // once "pReplyBuffer" is no longer NULL I know that data has returned.
>
> But I have 2 problems
>
> 1) As you can see the wait is totally inadequate. it hangs the system. So
> what would be the best way to wait for a few seconds?
> What I am doing now is ::PeekMessage( &msg, 0, 0, PR_REMOVE), but I don't
> feel good handling ALL the messages that way.
> PeekMessages only for socket ones does not seem to work and still causes
the
> system to hang.
>
> 2) Sometimes the Send(..) -> (who then calls the SendChunk() function),
> simply hangs and waits forever for the PumpMessages(FD_WRITE) to return.
> What could I be doing wrong.
>
> Many thanks
>
> Simon
>
>


.



Relevant Pages

  • Re: CSocket, best way to wait for a reply?
    ... DWORD CurrentTicks = GetTickCount(); ... > Basically the client sends a message to the server and in turn the server ... > sends a message back to the client. ... > simply hangs and waits forever for the PumpMessagesto return. ...
    (microsoft.public.vc.mfc)
  • Re: Issues with pdf files
    ... The client system's browser hangs while trying to access ... the file from the server. ... >mean A) the client machine accessing the PDF document ...
    (microsoft.public.sharepoint.portalserver)
  • Re: nfs tranfers hang in state getblck or nfsread
    ... > Reboot the client system, reboot, and remount ... > Thrash the file system a bit with large reads/writes, and it hangs ... As my server "never" shuts down and the 5-current client is switched off ... In my case there's no server reboot. ...
    (freebsd-current)
  • CSocket, best way to wait for a reply?
    ... Basically the client sends a message to the server and in turn the server ... void MyMessage(void *pData, int nSize) ... simply hangs and waits forever for the PumpMessagesto return. ...
    (microsoft.public.vc.mfc)
  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)