473,395 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
2 1585
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Frank Bechmann | last post by:
I started to write a SciTe director in python. I had a very basic communication running in Pythonwin but I disliked the strong mixture between Pythonwin's basic functionality and the Pythonwin...
4
by: John Bailo | last post by:
AJAX demo: http://texeme.com/ajaxtest.html -- Texeme Construct http://texeme.com
8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
1
by: BilMuh | last post by:
Hello Developpers, I am developping a TCP/IP Client application using Visual C++ .NET Standard on Windows 2000 Pro. I noticed that I could not receive more than 2KB once at a time. The server...
0
by: Shoveler | last post by:
I've got an odd problem here that I've been beating my head on for days. I've written a class that uses a pre-established connection for communication, meaning I can use this class for a server or...
2
by: Andreas | last post by:
Hello I have a Problem with my UDP communication. I will receive data from a known Target, but after a timeout i will abort the receive. has anybody an idea how to make this.
0
by: ktg024 | last post by:
Hi all, I am beginner to VC++, I am trying to transmint and receive data through serial port using MSCOM. I am able to transmit data but I am unable to receive the data here is my receive...
3
by: Joe Blauth | last post by:
Hi all, I am currently working on a small application that sends messages from a client to a server and receives messages in return. Basically the functionality is made with sockets which is...
4
by: folen | last post by:
Hi to every body, I am reading this forum since about two weeks, this forum has solved a lot of question that i had, thank to every body. I have a question about messages (WM_PAINT, etc...) in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.