Re: How to deal with full-duplex communication?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 30 May 2006 05:14:16 -0400
Note that TCP/IP guarantees that everything that is sent is received in the order it was
sent. Beyond that, any complex asynchronous protocols have to be designed to be
resilient, as already pointed out. If A sends a message to B, and the only thing B can do
is ACK/NAK it before A sends another message, there should be no problem. But if you have
messages sent like
A1 A2 A3 B2 B1 B3
makes perfect sense because the message A1 may require more computing on the other side
than A2, so B2, the response to A2, will be sent by B before it completes the processing
of A1 and sends the B1 response.
TCP/IP itself will not and cannot "lose" messages. If you are seeing message lossage, it
is an error in your protocol. In fact, protocol design can be very complex in a
completely asynchronous system where the messages interact; if the messages are
independent, however, with their responses, then each side has to be completely driven by
what is coming back, completely asynchronously as part of the design.
Overall, it sounds like you have a fundamental design error in your protocol, because I've
done a lot of asynchronous TCP/IP with complex protocols and the underlying mechanism
works perfectly. Any errors you are seeing are almost certainly a problem with your
design.
joe
On Sat, 27 May 2006 08:03:01 +1000, Ian Semmel <isemmelNOJUNK@xxxxxxxxxxxxxxxxxxxxxxx>
wrote:
The 'Async' part of the class name is the key to this sort of problem.Joseph M. Newcomer [MVP]
At the level of socket io, you cannot really coordinate sending and receiving,
as this just happens at any old time when windows feels like it.
As messages are assembled at the socket level (which I always put in a separate
thread), you should post complete messages to a higher level (eg the main gui
thread) which can then work out the logic of what to do next.
fadics wrote:
Thank you.
The return receipt I use is the size of all received data. So I can know
which message has been received. But the problem is still there. When both
side send and receive data at same time, the return receipts can not be
sent. Because they don't know whether the last message has been received. If
I send the return receipt immediately regardless of the receiving of other
side, the return receipt may be lost. By the way, I use TCP with
CAsyncSocket. But the lost is still on. I add watch to the OnReceive
function. The return receipt was not received.
Thank you anyway.
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> ????
news:uYxn9e$fGHA.356@xxxxxxxxxxxxxxxxxxxxxxx
fadics wrote:
I use CAsyncSocket class.
When A receives a packet, it sends a return receipt to B. B does the
same.
When A and B send a packet at the same time, they receive the receipt of
previous packet. So they wait the last receipt at the same time. The
communication breaks. How to solve this problem.
Thank you for any answer. A sample is welcome more.
Your protocol logic must be prepared to process whatever it receives.
It cannot assume that the next message must be a return receipt. If
your return receipts contain a serial number of the message being
acknowledged then you can maintain a list of pending receipts. (It is
possible you will receive several messages before receiving a receipt.)
--
Scott McPhillips [VC++ MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Re: How to deal with full-duplex communication?
- From: Scott McPhillips [MVP]
- Re: How to deal with full-duplex communication?
- From: Ian Semmel
- Re: How to deal with full-duplex communication?
- Prev by Date: Re: QueryPerformanceCounter
- Next by Date: Re: VC++
- Previous by thread: Re: How to deal with full-duplex communication?
- Next by thread: Re: ASCII Conversion
- Index(es):
Relevant Pages
|
|