That approach should work - most of the time. However, if the response
doesn't come back fast enough your program will fail on the recv() and
not realize there is still data coming.

With the select() statement you can specify a timeout value. The
select() waits for a response from the socket indicating its status
and will return to your program when it receives a response or it
times out. If there is data waiting the select() returns immediately
and you know you need to recv() the data. If it times out then you can
continue. The timeout value is set in microseconds and/or seconds.

Look on Scott's web page for an explanation on how to use it.

Albert

On Fri, Jan 28, 2011 at 6:38 AM, hockchai Lim
<lim.hock-chai@xxxxxxxxxxxxxxx> wrote:
Scott,
It should always be a one to one relationship between the send and recv.  My
application sends one command and will recv one respond back from the
server.  Yes, in theory, I could send all three commands and then recv all
three responds back at once.  But this senario will not happen in this
application.

The server is actually not a true socket server application.  It is actually
a modem (v.35) type application.  The network guy puts a CISCO route, that
speak TCP/IP, in between my socket app and the actual modem server.  So, my
app actually speck to this CISCO route and it then sends the data to the
target server.  Sometime if the CISCO route is not configured correctly,
I'll see the respond being echo back to me (seeing the same respond twice).
So, I'm kind of worry that this echoing problem might throw my app to become
out of sync on this one to one send and recv relationship.

Albert,
I've never had a chance to use select() api.  So, I'll have to look more
into this.  I was thinking recv() in non-blocking mode will flush this
echoing problem and hence keeps my send() and recv() in sync.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.