Re: Problems with CAsyncSocket.
- From: "Michael K. O'Neill" <MikeAThon2000@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 13:29:59 -0800
"AliR" <AliR@xxxxxxxxxxxxx> wrote in message
news:442af4df$0$3334$a8266bb1@xxxxxxxxxxxxxxxxxxxxxx
You will have to put your Receive calls in a loop. Each call to Receivecalling
can give you a portion of what's available, so you will have to keep
receive until it returns a 0 (meaning there is nothing left).
AliR.
For asynchronous sockets like CAsyncSocket, don't call Receive() more than
once in OnReceive(). The winsock message paradigm is designed so that it
expects you to call Receive() exactly once inside OnReceive(), and no more.
If winsock has more data for your application after the single call to
Receive(), then it will issue another FD_READ which in turn triggers another
call to OnReceive().
See http://support.microsoft.com/kb/185728/EN-US/
Combined with the answers given below by Josh McFarlane, the OP should now
understand that TCP is a stream-based protocol that has no knowledge of the
packets (or chunks or messages) in which the data is sent to the receipient.
This usually means that the sender and receiver must agree on some sort of a
protocol for sending data and deciphering received data. One of the
simplest protocols is to pre-pend each message with the length of the
message before it's sent. On receipt, the recipient waits until it has
received the specified number of bytes before it processes the data, and
saves any residual data it has already received from the beginning of a next
message.
See this too: "How to Use TCP Effectively" at
http://tangentsoft.net/wskfaq/articles/effective-tcp.html
Mike
.
- Follow-Ups:
- Re: Problems with CAsyncSocket.
- From: AliR
- Re: Problems with CAsyncSocket.
- References:
- Problems with CAsyncSocket.
- From: TonyG
- Re: Problems with CAsyncSocket.
- From: AliR
- Problems with CAsyncSocket.
- Prev by Date: Re: Problems with CAsyncSocket.
- Next by Date: Re: a container supports keys (similar to the set in STL)
- Previous by thread: Re: Problems with CAsyncSocket.
- Next by thread: Re: Problems with CAsyncSocket.
- Index(es):
Relevant Pages
|