473,625 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

socket packet size = bandwidth?

This may be the dumbest question of all time, but...

When I set the packet size, does it mean ALL packets are that size, no
matter what? Let's say the packet size is 8KB, and I send a 5 byte
"hello", will it cause 8KB of bandwidth, or 5 bytes (plus TCP/IP
packet header, as well, of course).

(Btw, I 'set' the packet size via Socket.BeginRec eive(), in the "size"
field = "The number of bytes to receive." Which seems to imply the
answer is YES.)

My concern is that I want to reduce bandwidth... but things are
'nicer' when the packet size is large so that everything comes in one
go, so I just defaulted to that, but, now b/w is an issue.

Zytan
Jul 24 '08 #1
4 7059
This may be the dumbest question of all time, but...
>
All due respect, it is at the very least poorly worded. :)
LOL
If you are asking a question that involves calling Socket.BeginRec eive(),
why is your hypothetical case described as "I send a 5 byte 'hello'"? Are
you asking about sending, or about receiving?
Sorry, I meant receiving 5 bytes. Most of my bandwidth is receiving
data, so this is the important part.

(I use Socket.Send(), obviously, to send data, and that takes an array
of byte, byte [], and I make that whatever size it needs to be at the
time, so I assume that this only uses as much bandwidth as is required
for the bytes and the packet header.)
And is the question about a
UDP socket or TCP socket?
TCP. (I know there's extra packets to ensure proper sequencing of
data, I'm ignoring this for now.)
If you are receiving data, you cannot rely on expecting that "everything
comes in one go", even if larger buffer sizes usually allow that to
happen. A successfully completed receive may result in anywhere from 1
byte all the way up to the buffer size actually being received for that
completion.
Right. The buffer size could be 16,384 bytes, and you send me
"hello", which is 5, and I get 5, and that was a success.
I also would not use the word "packet" to describe the size of your
buffer. At best, if you are _sending_ and you are using UDP, the buffer
length passed to the sending method would define the size of the datagram
itself. But "packets" exist at a lower level than that, and the size of
what most people are actually calling "packets" are unaffected by how an
application sends the data.
Right, if I send 100,000 bytes, it could be sent off as 4 KB packets
underneath, regardless that this is presented to me, the programmer,
as though it was sent "all as one".
If you can either clean up the question so that you're describing it more
precisely, or you can post some code that is exactly what you're talking
about, it'd probably be possible to provide a better answer. Based on
what you've asked so far, all I can say is that when you call a sending
method, the method will send exactly as many bytes as you asked it to (*)
and when you call a receiving method, the method will receive any number
of bytes between 1 and the number of bytes you told it are available in
your receive buffer.
Ok, so for Socket.BeginRec eive(), if I tell it I want to accept a
16,384 byte buffer from the internet... and some data comes in from
your PC that says "hello", I call Socket.EndRecei ve() to get the data,
which returns the number of bytes I got. Which would be 5 for
"hello", and I assume that just because the data buffer COULD accept
16,384 bytes, it would have only used 5 bytes of bandwidth (ignoring
packet headers).

Thanks, Pete!

Zytan

Jul 24 '08 #2
On Thu, 24 Jul 2008 13:16:55 -0700, Zytan <zy**********@g mail.comwrote:
This may be the dumbest question of all time, but...
All due respect, it is at the very least poorly worded. :)
When I set the packet size, does it mean ALL packets are that size, no
matter what? Let's say the packet size is 8KB, and I send a 5 byte
"hello", will it cause 8KB of bandwidth, or 5 bytes (plus TCP/IP
packet header, as well, of course).

(Btw, I 'set' the packet size via Socket.BeginRec eive(), in the "size"
field = "The number of bytes to receive." Which seems to imply the
answer is YES.)
If you are asking a question that involves calling Socket.BeginRec eive(),
why is your hypothetical case described as "I send a 5 byte 'hello'"? Are
you asking about sending, or about receiving? And is the question about a
UDP socket or TCP socket?
My concern is that I want to reduce bandwidth... but things are
'nicer' when the packet size is large so that everything comes in one
go, so I just defaulted to that, but, now b/w is an issue.
If you are receiving data, you cannot rely on expecting that "everything
comes in one go", even if larger buffer sizes usually allow that to
happen. A successfully completed receive may result in anywhere from 1
byte all the way up to the buffer size actually being received for that
completion.

I also would not use the word "packet" to describe the size of your
buffer. At best, if you are _sending_ and you are using UDP, the buffer
length passed to the sending method would define the size of the datagram
itself. But "packets" exist at a lower level than that, and the size of
what most people are actually calling "packets" are unaffected by how an
application sends the data.

If you can either clean up the question so that you're describing it more
precisely, or you can post some code that is exactly what you're talking
about, it'd probably be possible to provide a better answer. Based on
what you've asked so far, all I can say is that when you call a sending
method, the method will send exactly as many bytes as you asked it to (*)
and when you call a receiving method, the method will receive any number
of bytes between 1 and the number of bytes you told it are available in
your receive buffer.

(*) Exception: note that a Socket in non-blocking mode using the
synchronous Send() method may send fewer bytes than you have told it to.
You have to check the return value to see what was actually sent.

Basically, don't tell Socket to send 8K if you don't want it to send 8K.

Pete
Jul 24 '08 #3
On Thu, 24 Jul 2008 14:10:17 -0700, Zytan <zy**********@g mail.comwrote:
[...]
Ok, so for Socket.BeginRec eive(), if I tell it I want to accept a
16,384 byte buffer from the internet... and some data comes in from
your PC that says "hello", I call Socket.EndRecei ve() to get the data,
which returns the number of bytes I got. Which would be 5 for
"hello", and I assume that just because the data buffer COULD accept
16,384 bytes, it would have only used 5 bytes of bandwidth (ignoring
packet headers).
Yes, that's correct. The only real downside for the larger buffer is the
memory consumption locally. Generally speaking, larger buffers provided
to the Socket _improve_ performance, because you have to transition back
and forth between your application code and the network driver fewer
times. Of course, beyond a certain point (16K is a good number) you get
diminishing returns, but up to that point, larger is better.

Obviously, for modern computer systems, 16K is a trivially small buffer in
terms of memory consumption. So you might as well use something about
that size. The biggest things I'd worry about are a) if you were
allocating a lot of these buffers (handling a large number of connections,
for example), and b) keeping the buffer smaller than the threshold for
allocations winding up in the large-object heap (at 16K you'd be well
under that threshold though).

Pete
Jul 24 '08 #4
Yes, that's correct. The only real downside for the larger buffer is the
memory consumption locally.
Right.
Generally speaking, larger buffers provided
to the Socket _improve_ performance, because you have to transition back
and forth between your application code and the network driver fewer
times.
Yes.
Of course, beyond a certain point (16K is a good number) you get
diminishing returns, but up to that point, larger is better.
Understood.
Obviously, for modern computer systems, 16K is a trivially small buffer in
terms of memory consumption. So you might as well use something about
that size.
I will do that.
The biggest things I'd worry about are a) if you were
allocating a lot of these buffers (handling a large number of connections,
for example), and b) keeping the buffer smaller than the threshold for
allocations winding up in the large-object heap (at 16K you'd be well
under that threshold though).
I only have one such buffer, so it's not a big deal.

Thanks for the tips, Pete!! :)

Zytan

Jul 25 '08 #5

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

Similar topics

30
10926
by: Richard | last post by:
Level: Java newbie, C experienced Platform: Linux and Win32, Intel Another programmer and I are working on a small project together. He's writing a server process in Java that accepts input from processes I've written over a TCP connection. My processes are all written in C; his are all done in Java. He's new to Java, and I've never really used it. My input is basically a stream of 32-bit unsigned integers (e.g., the
4
41848
by: Stephan Steiner | last post by:
Hi I have a networking application that periodically needs to go into sleep mode (from an application point of view, I'm simply suspending the receiver thread until it's time to start listening to incoming packets again). The packets I'm interested in are UDP broadcasts, so they are simply dropped when nobody application is listening at the specified port. However, when I initialize my receiver, there's a socket listening at the...
3
7790
by: Stephan Steiner | last post by:
Hi I have a small program listening to UDP broadcast datagrams that are periodically sent out. It will stop listening for a certain period if either a sufficient number of packets has been received (this is triggered from a class not in the sample code), or if there has been no data on the net for a certain period. During the time where I don't want any packets, I set my socket receive buffer size to zero. The problem is, when I used...
0
11850
by: Stephan Steiner | last post by:
Hi The project I'm currently working on involves sending large UDP broadcasts. As the .NET framework already provides an easy facility for sending and receiving UDP packets I thought it was a good idea to use UdpClient rather than sockets directly. A few weeks back I ended up rewriting the receiver part to use sockets directly because I had to manipulate some low level socket properties, and those manipulations would fail on the...
12
16897
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons there is not a one to one map between a session and a physical TCP connection. A client may disconnect the TCP connection if it is idle for more than 60 seconds... yet a conceptual "session" may last for days at a time. It's necessary that the...
5
3679
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose but have been unsuccessful in finding the answers so far. Either because my understanding of sockets isn't where it needs to be or my questions are too basic. My programming environment is Windows XP, Visual Studio .NET 2003 and C#. So here it...
2
4654
by: Macca | last post by:
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.
9
3596
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.
0
4670
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.
0
8251
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8182
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8352
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6115
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.