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

Socket Server buffer size

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
> 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

P: n/a
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***@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.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 discussion thread is closed

Replies have been disabled for this discussion.