By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,101 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,101 IT Pros & Developers. It's quick & easy.

Could not receive more than 2KB at TCP/IP communication!

P: n/a
Hello Developpers,
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.

As a note, I am using MS Visual C++ .NET Standard on Windows 2000 Professional O.S.

I searched over internet about how to resize the recv( ) buffer. I understood that TCPWindowSize is the point that I have to work on. Or there are some other settings that I don't know now.

If you may guide me about resizing the recv(...) buffer, I will be so happy.

Respectfully, yours

Alper
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
setsockopt SO_RCVBUF sets receive buffer size
But your app behaved correctly - with stream-oriented sockets (SOCK_STREAM,
that is when you use IPPROTO_TCP) you receive data as a stream of bytes, so
you don't know particular sizes of each send at server size. It's known whe
using SOCK_DGRAM sockets. If server sends to you 4KB data throught TCP, you
can receive it in 1,2,3,4,5 or 10 different-size parts.
Nov 17 '05 #2

P: n/a
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
to****@mvps.org
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.