473,554 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Server buffer size

Hi,

My application uses an asynchronous socket server. The question I have is
what i should set my socket server buffer size to.

I will know the size of each data packet sent across the network and was
considering setting the buffer size to this.

In the examples I have seen on the net the buffer size is usually set to
1024 bytes and the socket is continually read until all data is received.

I'd like to avoid repeatedly reading socket to get full data packet since I
will know how big the packet will be in advance.

My data will be bigger than this e.g 10KB but will this buffer size impact
on performance and therefore be better to use a smaller buffer and read the
socket repeatedly?

I'd appreciate any advice.

Thanks In Advance
Macca
Feb 12 '06 #1
2 4652
> In the examples I have seen on the net the buffer size is usually set to
1024 bytes and the socket is continually read until all data is received.

I'd like to avoid repeatedly reading socket to get full data packet since
I
will know how big the packet will be in advance.
There is no guarantee that you will receive all the data via one Receive
call.
Especially if you have large data chunk, you may not receive whole data.
My data will be bigger than this e.g 10KB but will this buffer size impact
on performance and therefore be better to use a smaller buffer and read
the
socket repeatedly?


You can allocate 10 Kb of memory to store received data, and small buffer
that
will be used in the Receive method. After each receive you'll be appending
data.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 12 '06 #2
Your receives can get 0, or 1 or more bytes. 0 means socket closed by client
side. So you have a two step process here:
1) Receive 4 bytes for len (or what ever your len type is). Still have to
loop until 4 bytes.
2) Recive Len bytes in your buffer until you get Len bytes in your loop.

I would leverage the same helper method for both. Something like "public
byte[] FillBuffer(int size){//Get size bytes from socket}"

--
William Stacey [MVP]

"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:C5******** *************** ***********@mic rosoft.com...
| Hi,
|
| My application uses an asynchronous socket server. The question I have is
| what i should set my socket server buffer size to.
|
| I will know the size of each data packet sent across the network and was
| considering setting the buffer size to this.
|
| In the examples I have seen on the net the buffer size is usually set to
| 1024 bytes and the socket is continually read until all data is received.
|
| I'd like to avoid repeatedly reading socket to get full data packet since
I
| will know how big the packet will be in advance.
|
| My data will be bigger than this e.g 10KB but will this buffer size impact
| on performance and therefore be better to use a smaller buffer and read
the
| socket repeatedly?
|
| I'd appreciate any advice.
|
| Thanks In Advance
| Macca
Feb 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
11670
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine...
7
2370
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew what they were doing could take a look at my code and tell me where and why I'm going wrong. Any suggestions of groups or forums?
9
3590
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so that its buffer is bigger than this. I did this expecting the data to be read in one pass.
2
6863
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless there is a problem with the connection. I need to know which client has sent the incoming data as each client has its own buffer on my "server"...
0
4659
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a number of different types of data coming in. I have a databuffer for each type of data coming in.
1
17535
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to another program for information passing. Upon receiving a particular "command" from the the information passing program, myProblemProgram will...
5
15704
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable to read data from the transport connection" when restart reading the stream with socket.BeginRead in the Sub SocketIncomingMsg. I'm debugging now for...
0
3558
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is supposed to do the following: monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but...
1
7138
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN site, which is actually for sending strings. I tried to adapt this code so that the client sends an image instead of a string. However, there is...
0
7615
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7539
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7819
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7897
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5446
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5165
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2030
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.