473,591 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the minimum-size UDP packet?

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 server keep track of all open sessions. The way
I'm planning to handle this is to have the client send it's session ID
[which is 4 bytes long] to the server every 2 minutes via UDP. The server
will respond via UDP with a one bit (datatype='bit' ) reply of either yes or
no. If the server hasn't received a valid session ID via UDP from the client
in over 10 minutes, the server will assume that the client is gone and will
close out the "session."

With that as the background, here are my questions:

1) I understand that UDP is a best-effort protocol and delivery of the
packets is not guaranteed. My system can tolerate that. What it *can't*
tolerate is only "part" of the client's UDP notification making it across
the wire. Recall that the client's UDP notification is 4 bytes long. I can't
tolerate a situation in which only 2 bytes get through [without the server
being made aware that some sort of error has occurred via a Winsock
exception]. It should be 4 bytes or none at all. Is UDP suitable for my
needs?

2) Is there a "minimum packet size" for UDP? In other words, when my
client sends a payload of 4 bytes to the server, are there actually more
bytes going across the wire due to a minimum packet size? I'm not too
up-to-speed on TCP/IP, but I know that there is something called a minimum
transmission unit (MTU) which can be set as high as 1,500 bytes or so. Will
my 4-byte notification be "padded" with 1,496 extra bytes? It's very
important that I get an answer to this question because my app needs to
conserve bandwidth [I may have 1000's of simultaneous "sessions" at any
given time].

Thanks in advance for any help you can provide!

--
Sincerely,

David Sworder
http://www.CodeFanatic.com
Nov 15 '05 #1
12 16892
_
David,
1) I understand that UDP is a best-effort protocol and delivery of the
packets is not guaranteed. My system can tolerate that. What it *can't*
tolerate is only "part" of the client's UDP notification making it across
the wire.
Stay under the MTU and you will either see the entire packet or none of it.
2) Is there a "minimum packet size" for UDP? In other words, when my
client sends a payload of 4 bytes to the server, are there actually more
bytes going across the wire due to a minimum packet size?


No - there is some overhead associated with the packet but there is no _minimum_
size (uh, actually I haven't tried sending zero bytes <g>).
--
Abderaware
Fine Components For .NET
Turn on, tune in, download.
zane a@t abderaware.com
Nov 15 '05 #2
"David Sworder" <Gi********@CSI LasVegas.com> wrote in message
news:uz******** ******@TK2MSFTN GP12.phx.gbl...
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 server keep track of all open sessions. The way I'm planning to handle this is to have the client send it's session ID
[which is 4 bytes long] to the server every 2 minutes via UDP. The server
will respond via UDP with a one bit (datatype='bit' ) reply of either yes or no. If the server hasn't received a valid session ID via UDP from the client in over 10 minutes, the server will assume that the client is gone and will close out the "session."

With that as the background, here are my questions:

1) I understand that UDP is a best-effort protocol and delivery of the
packets is not guaranteed. My system can tolerate that. What it *can't*
tolerate is only "part" of the client's UDP notification making it across
the wire. Recall that the client's UDP notification is 4 bytes long. I can't tolerate a situation in which only 2 bytes get through [without the server
being made aware that some sort of error has occurred via a Winsock
exception]. It should be 4 bytes or none at all. Is UDP suitable for my
needs?

2) Is there a "minimum packet size" for UDP? In other words, when my
client sends a payload of 4 bytes to the server, are there actually more
bytes going across the wire due to a minimum packet size? I'm not too
up-to-speed on TCP/IP, but I know that there is something called a minimum
transmission unit (MTU) which can be set as high as 1,500 bytes or so. Will my 4-byte notification be "padded" with 1,496 extra bytes? It's very
important that I get an answer to this question because my app needs to
conserve bandwidth [I may have 1000's of simultaneous "sessions" at any
given time].

Thanks in advance for any help you can provide!

--
Sincerely,

David Sworder
http://www.CodeFanatic.com

David,

1) You will get either all or none of the datagram. Is UDP for you? I will
list some pro/cons of each TCP & UDP and let you decide.

UDP:
Connectionless - there is no connection. "sessions" are frequently used to
simulate a connection. Since there is no connection, you don't know when it
is broken (other end disconnects). The host typically removes a client when
it hasn't received some sort of pulse (in your case, session ID) datagram.
This can happen some time after the other device actually shuts off, which
may be good or bad for you.

Less overhead than TCP - datagrams are sent once, either they make it or
they don't make it.

Packet based - you are dealing with datagrams (packets).

TCP:
Connection based - both ends know when the peer has broken the connection

More overhead than UDP - frames (packets for TCP) will be resent if the
other side does not acknowledge them. This is less efficient than UDP, but
when you build ACK/retries/order into UDP they end up at about the same
efficiency level.

Stream based - you are dealing with a continious stream of data. You can
treat the stream like packets but it is not really the idea.

Those are the strong points. There are tons of arguments favoring each
protocol on the internet if you are looking for more information.

2) The minimum datagram size is 1 byte. MTU means MAXIMUM transmit unit,
not minimum. For a UDP packet, the Winsock stack will send across another
20 bytes (12 for IP header, 8 for UDP header) over the wire. These 20 bytes
are the UDP/IP headers which are required, they are not pad bytes. 1500 is
the "standard" MTU for UDP datagrams. I get best results when I set my MTU
to 512. YMMV.

Of course, this is all just my 0.02.
Nov 15 '05 #3
Thanks Zane and Trevor...

That's great information. Given the large overhead (relatively speaking,
given my small payload size) of UDP, I'm wondering if it might be better to
just keep the TCP connection in place at all times. I imagine this would
eliminate the need for keepalives. The downside is that the server could be
maintaining 1000's of idle connections at any given time. Here's another
somewhat related question:

Let's say that the client and server have a TCP connection in place. The
client then unplugs his network cord [or takes some other action to
abnormally disconnect his computer without the server receiving a TCP/IP
notification that the connection has closed]. How long will it take before
my server realizes that the connection is dead? Does TCP/IP have it's own
mechanism of testing for downed connections?

--
Sincerely,

David Sworder
http://www.CodeFanatic.com
Nov 15 '05 #4
David,

See inline...

"David Sworder" <Gi********@CSI LasVegas.com> wrote in message
news:u9******** ******@TK2MSFTN GP10.phx.gbl...
Thanks Zane and Trevor...

That's great information. Given the large overhead (relatively speaking, given my small payload size) of UDP, I'm wondering if it might be better to just keep the TCP connection in place at all times. I imagine this would
eliminate the need for keepalives. The downside is that the server could be maintaining 1000's of idle connections at any given time. Here's another
somewhat related question:

I didn't mention in my other post that I have developed two systems (1 for
TCP, 1 for UDP) identical to the one you are developing. I use sessions on
top of TCP for my TCP implementation. By sessions, I mean basically I send
a login packet (user/password) and then the host will start sending data to
me that is destined to that username. You should really consider making the
TCP server multi-threaded if you haven't done so. I chose to have one
thread for listening, 1 thread for all of the clients (it traverses a vector
of clients, sending/receieving for each client as needed).
Let's say that the client and server have a TCP connection in place. The client then unplugs his network cord [or takes some other action to
abnormally disconnect his computer without the server receiving a TCP/IP
notification that the connection has closed]. How long will it take before
my server realizes that the connection is dead? Does TCP/IP have it's own
mechanism of testing for downed connections?

I don't know about .NET, but the native API recv() will tell you right away
if the client disconnected (without needing to receive data). Java would
throw an IOException the next time you try to read/write to a broken socket.
I am sure .NET works like the Java implementation. Even if the .NET version
does not work like this, it is possible to make one that does.
--
Sincerely,

David Sworder
http://www.CodeFanatic.com



Nov 15 '05 #5
> TCP server multi-threaded if you haven't done so. I chose to have one
thread for listening, 1 thread for all of the clients (it traverses a vector of clients, sending/receieving for each client as needed).


Cool. Whats a vector? An arraylist? Does that thread just keep looping on
the list to find some work in a slot or does it block on some event(s)? TIA

--
William Stacey, MVP

Nov 15 '05 #6
Answers to the questions below then some general answer from previous
questions

1) If no data is being sent between a client and a server, TCP as a protocol
has keepalive mechanims to verify the connection is still alive; however,
this is not turned on by default in Windows. If the peer dies in a way the
remote endpoint doesn't receive any information, the connection will just
sit there in the default setting. If you try to send data on this connection
then it can be detected the peer has died and you will receive notification
but if you don't then you won't know if it is active or not. However, you
can enabled keepalive with setsockopt().

2) MTU stands for maximum transmission unit and controls how many bytes can
be sent in each frame on a certain link. The minimum size you are thinking
of may be the minimum required on the physical link - for example, ethernet
frames have a minimum size and the network card will pad the frame to meet
the size requirement so collisions on the wire can be detected. Protocols
using the link do not have to worry about this and neither do you.

3) UDP packets can contain no bytes. Because UDP is a packetized protocol
sending 0 bytes is acceptable; if you try to do this in TCP, which is a
stream protocol, then nothing will go on the wire.
Stephanie

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"David Sworder" <Gi********@CSI LasVegas.com> wrote in message
news:u9******** ******@TK2MSFTN GP10.phx.gbl...
Thanks Zane and Trevor...

That's great information. Given the large overhead (relatively speaking, given my small payload size) of UDP, I'm wondering if it might be better to just keep the TCP connection in place at all times. I imagine this would
eliminate the need for keepalives. The downside is that the server could be maintaining 1000's of idle connections at any given time. Here's another
somewhat related question:

Let's say that the client and server have a TCP connection in place. The client then unplugs his network cord [or takes some other action to
abnormally disconnect his computer without the server receiving a TCP/IP
notification that the connection has closed]. How long will it take before
my server realizes that the connection is dead? Does TCP/IP have it's own
mechanism of testing for downed connections?

--
Sincerely,

David Sworder
http://www.CodeFanatic.com

Nov 15 '05 #7
William,

Yes, a vector is similar to an ArrayList. The thread uses
WaitForMultiple Objects and blocks for Winsock & file system events.
Nov 15 '05 #8

I didn't mention in my other post that I have developed two systems (1 for
TCP, 1 for UDP) identical to the one you are developing. I use sessions on top of TCP for my TCP implementation. By sessions, I mean basically I send a login packet (user/password) and then the host will start sending data to me that is destined to that username. You should really consider making the TCP server multi-threaded if you haven't done so. I chose to have one
thread for listening, 1 thread for all of the clients (it traverses a vector of clients, sending/receieving for each client as needed).


I do have 1 thread for listening as you do, but I handle incoming data
using the thread pool. As soon as a connection is accepted, I do a
BeginReceive() against the newly accepted socket. BeginReceive() returns
immediately. A thread from the thread pool will wake up when data is
received and the appropriate processing takes place. The thread pool
optimizes how many running threads from its pool are in use at any given
time, but from what I understand it tries to make the number of running
threads match the number of CPUs in the machine. So since I'm running on a
dual processor machine, even if there are 1000 simultaneous connections, I
typically won't have more than two threads receiving data at the same
time... at least this is my understanding of how this approach is supposed
to work. The goal is to keep the CPUs busy and keep the number of threads
low to avoid a context switching penalty. If, while processing data, one of
my thread-pool threads enters a blocking state [i.e perhaps to connect to a
database], the thread pool senses that a thread is blocked and automatically
frees up another thread to receive more data from another one of the
connections... kind of a neat approach. I read about it in MSDN.
David
Nov 15 '05 #9
Hi Stephanie,

Thanks for your reply. See inline...
1) If no data is being sent between a client and a server, TCP as a protocol has keepalive mechanims to verify the connection is still alive; however,
this is not turned on by default in Windows. If the peer dies in a way the
remote endpoint doesn't receive any information, the connection will just
sit there in the default setting. If you try to send data on this connection then it can be detected the peer has died and you will receive notification but if you don't then you won't know if it is active or not. However, you
can enabled keepalive with setsockopt().
How often is the keepalive packet sent across the wire?

2) MTU stands for maximum transmission unit and controls how many bytes can be sent in each frame on a certain link. The minimum size you are thinking
of may be the minimum required on the physical link - for example, ethernet frames have a minimum size and the network card will pad the frame to meet
the size requirement so collisions on the wire can be detected. Protocols
using the link do not have to worry about this and neither do you.


I think you're right. I'm thinking of the minimum size required on the
physical link. Here's my concern: I get charged based on how much bandwidth
I use. Bandwidth is monitored by a router at a colocation facility which
looks at how much data I pass over their network. If I sent 5 bytes of data
via UPD and the minimum transmission size for Ethernet is 1500 bytes, won't
my NIC wrap by 5 byte payload in 1500 bytes? And won't that router that is
monitoring my useage charge me for 1500 bytes? Perhaps that's something that
I should ask Verio, but hopefully you see what I'm getting at.
--
Sincerely,

David Sworder
http://www.CodeFanatic.com
Nov 15 '05 #10

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

Similar topics

6
23484
by: WindAndWaves | last post by:
Hi Folks I have inhereted a script that I understand reasonably well, I just do not understand !/^\d+$/.test(el.value) what the hell does that mean? Below is the script (there are really three and they validate a four items
3
9069
by: RobG | last post by:
I would like a query that will tell me the minimum non-zero value in a row. Say I have a table with a column called recordID that contains unique record IDs, and have a set of values named V1, V2 up to V9 that I want to find the minimum value for each record. The values are decimal floating point numbers, some of the columns contain zeros but I want to ignore those and get the minimum non-zero number. I know how to do column sorting,...
86
3889
by: Randy Yates | last post by:
In Harbison and Steele's text (fourth edition, p.111) it is stated, The C language does not specify the range of integers that the integral types will represent, except ot say that type int may not be smaller than short and long may not be smaller than int. They go on to say, Many implementations represent characters in 8 bits, type short in
3
1474
by: Joseph | last post by:
Has anyone implement a mechanism to retain the cache up to a minimum cache time even though it is supposed to get invalidated? I asked this because I don't want to increase the load on the database server for caches that are frequently invalidated and a database retrieval is required. I want to be able to keep the cache and use it within a specified small period of time (the minimum cache time mentioned above). thanks, Joseph
1
7914
by: itsolutionsfree | last post by:
Hi All, i am deep trouble.so,please help me how to get minimum and maximum dates for particular Month and Year.Any kind of help will help. for ex: im passing : March 2006 Minimum Date - 01/March/2006 Maximum Date - 31/March/2006
11
8762
by: JJLaRocque | last post by:
Hi all, Is there a simple python function to return the list index of the minimum entry in a list of lists? ie, for , , ] to return 2,4. Or, same question but just for a list of numbers, not a list of lists. Thanks, Josh
3
2077
by: manxie | last post by:
Dear All Readers, I'm supposed to create a program with a switch and using voids to execute number of codes, that includes finding sum, average, maximum, and minimum, please read my code: #include <iostream> #include <string> #include <iomanip> using namespace std; void WELCOME();
13
2726
by: Ioannis Vranos | last post by:
Is there any mentioning in the standard of the number of bits of the various built in types, apart from char/signed char/unsigned char types? Or only about the minimum value ranges of them?
2
3998
by: James Harris | last post by:
I'm trying to make sense of the standard C data sizes for floating point numbers. I guess the standards were written to accommodate some particular floating point engines that were popular at one time but I can only find references to the number of decimals etc. Basically, if I wanted to specify C-sized reals in a language that only accepted bit- widths, e.g. float(exponent 8, mantissa 24) I'm looking for what numbers would be needed...
6
1897
by: raylopez99 | last post by:
Will ASP.NET 3.0 work under Visual Studio 2005? And what is a good newbie ASP.NET book? Subject: Will ASP.NET 3.0 work under Visual Studio 2005? And what is a good newbie ASP.NET book? My question is in the title. I have experience with C#, SQL, C++/CLI and have done exercises in a book on database design, so I'm not a total beginner, but a recommendation for an intermediate book on ASP.NET is appreciated.
0
8362
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
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,...
0
8225
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6639
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5400
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
3850
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
2378
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
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
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.