Re: Could not receive more than 2KB at TCP/IP communication!
From: Tomas Restrepo \(MVP\) (tomasr_at_mvps.org)
Date: 06/11/04
- Next message: novice_win_snmp: "Re: Snmp Service and Community String"
- Previous message: DD: "GINA"
- In reply to: Alper Akcayoz: "Could not receive more than 2KB at TCP/IP communication!"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 11 Jun 2004 06:34:37 -0500
Alper,
> I faced with a problem during developping a TCP/IP Client application. The
Client application will receive intensive data from Server. Client is
receiving data by using the recv(...) functions, as normal. My code is as
follows:
>
> ----------
> public __gc class Form1 : public System::Windows::Forms::Form
> {
> ....
> public:
> #define Max_Buffer_Size 50000
> SOCKET ClientSocket;
> ......
>
> private:
> void trd_Recv_Task()
> {
> ....
> char* recvBuf = new char[Max_Buffer_Size];
> int retRecvVal = recv(ClientSocket , recvBuf , Max_Buffer_Size ,
0);
> .....
> }
> ....
> }
> ------------
>
> During this receiving, I noticed that I could not receive more than 2048
Bytes (2KB) once at a time. In my first version of code, I was taking data
from Server, then, doing operations depending on the received data. But
once, receiving data were more than 2KB, and I could not take then rest of
my working codes gave erros.
>
> I changed my technique now. First, I receive only a 2 bytes of data that
says me the size of the following receiving in integer format. Then I run
the recv(...) function in a while(...) loop, till the expected number of
bytes are received. The rest is working.
That's exactly how it is meant to be used. You loop until you get all bytes
you need.
The documentation clearly states "For connection-oriented sockets (type
SOCK_STREAM for example), calling recv will return as much information as is
currently available-up to the size of the buffer specified", which implies
that it might very well return less than you asked for. This is perfectly
normal behavior.
-- Tomas Restrepo tomasr@mvps.org
- Next message: novice_win_snmp: "Re: Snmp Service and Community String"
- Previous message: DD: "GINA"
- In reply to: Alper Akcayoz: "Could not receive more than 2KB at TCP/IP communication!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|