473,464 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

udp broadcast throughput difference: udpclient vs socket

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 underlying
socket of an UdpClient. One of my subsequent problems was that the sending
part did not perform as well as I wished. I have two NICs on my PC, and when
making broadcasts over the secondary one, things would come almost to a
standstill.. sending would happen at one packet per several seconds (packet
size 750 bytes), and only when I was lucky and disabled the primary NIC,
would sending performance be up to par.
However, when making large broadcasts it just took too long so I started
measuring how long it takes to send a packet. I used both Ethereal and
HiPerfTimer
(http://www.codeproject.com/useritems...timercshar.asp) and
found out that UdpClient.Send took roughly 5 ms for a 750 byte packet,
resulting in a throughput of 150'000bytes/second which is way below what a
100mbit card can do.

Subsequently, I rewrote the sender part to use sockets directly which had a
considerable impact on performance. Sending one packet now takes 0.64ms, and
the throughput increased to 1'160'360 bytes/second which is a considerable
improvement. It is however, still way below what the card can do (assuming a
NIC can use 20% of its bandwith in a real world scenario, my 100mbit card
should still make 2.5MB/s, not 1.16MB/s so it's still a factor two).
So, I'm concluding that
a) UdpClient is almost 8 times slower than using a socket directly
b) .net sockets are unable to saturate a good 100mbit NIC (the crappy
secondary card I have eventually starts dropping packets if the broadcast is
too large, so it gets saturated in a way.

Here's the code I've been using for my tests:

UdpClient (the class containing this code derives from UdpClient)

UdpClient updClient = new UdpClient(localPort);
Socket s = this.Client;
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
Byte[] packet = new Byte[packetSize];
int nBytesSent = 0;
Byte[] seqNr = null;
for (short i = 0; i < nbPackets; i++ )
{
nBytesSent = updClient.Send(packet, packet.Length, address, remotePort);
}

Sockets only:

sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast,
1);
IPEndPoint localhost = new IPEndPoint(IPAddress.Any, localPort);
sock.Bind(localhost);
IPEndPoint remotehost = new IPEndPoint(IPAddress.Parse(address),
remotePort);
EndPoint remoteEP = (EndPoint)remotehost;
byte[] packet = new Byte[packetSize];
int nBytesSent = 0;;
for (short i = 0; i < nbPackets; i++ )
{
nBytesSent = sock.SendTo(packet, remoteEP);
}

Comments are welcome.

Regards
Stephan
Nov 15 '05 #1
0 11836

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

Similar topics

4
by: Morten Overgaard | last post by:
Hi I'm listening on the SysLog port (514) through UDP. The problem is that I am not receiving anything nut I know that i get messages on the port. When I use KIWI to listen on the same port via...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
2
by: Rick | last post by:
Hi, I'm trying to get a simple UdpClient app working. I've been looking at the MSDN info regarding UdpClient. When I set it up on my own PC and send messages to myself it works OK. If I try to...
3
by: Ryan Learns Sharp | last post by:
Can anybody help and explain why? I wrote two programs just to test broadcasting in C#, which both run on the same machine. However, the receiver program can't receive any messages from the sender...
1
by: Steve | last post by:
Please take a look at the simple code segment below and advise me what is wrong. According to the help and examples I've seen it should work unless I misunderstand something. The problem is...
8
by: Frank Esser | last post by:
Hello! I have got machines that answer a certain UDP broadcast request with certain information about them. Some years ago I wrote a VB6 application that just sent out this UDP broadcast...
2
by: Shawn G. | last post by:
I'm going around in circles here and need some help. Scenario: I am using (have used) either the UDPClient class or Sockets class to broadcast some bytes to 255.255.255.255 (udp protocol). Upon...
7
by: GTi | last post by:
I need a code snippet for sending a message to all computers located on the same IP subnet. This is only a simple message like; "Here I am" I'm developing a server/client application. Instead of...
1
by: greenxiar | last post by:
My code is below and the platform is Win2K3 R2: using System; using System.Net; using System.Net.Sockets; using System.Threading; namespace TechUDPBroadcast { class Program { static void...
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
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...
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,...
1
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
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.