Socket and UdpClient when App is used under NT.

R

Richy Rich

Hi,

I've developed an application in C# which spawns a thread
to receive datagrams.

If I use the socket receive method, there are no problems
when using the application under NT or XP.

I recently moved over to using the UdpClient receive
method. This was so I could record the IPEndPoint from
the datagram received to determine the IP address of the
sender. Problem is, the UdpClient method seems to have
problems keeping up with the incoming datagram rate under
NT. This problem does not occur when using XP.

I could use the Socket receive from method as a work
around, but this uses an EndPoint and not an IPEndPoint
making the IP address of the sender impossilble to extract?

I am puzzled to why the UdpClient works differently under
NT?

Richy.
 
R

Rich Blum

Richy Rich said:
Hi,

I've developed an application in C# which spawns a thread
to receive datagrams.

If I use the socket receive method, there are no problems
when using the application under NT or XP.

I recently moved over to using the UdpClient receive
method. This was so I could record the IPEndPoint from
the datagram received to determine the IP address of the
sender. Problem is, the UdpClient method seems to have
problems keeping up with the incoming datagram rate under
NT. This problem does not occur when using XP.

I could use the Socket receive from method as a work
around, but this uses an EndPoint and not an IPEndPoint
making the IP address of the sender impossilble to extract?

I am puzzled to why the UdpClient works differently under
NT?
Richy -

You can still use the IPEndPoint class with the ReceiveFrom()
method, just typecast the results:

recv = sock.ReceiveFrom(ref ep);
IPEndPoint iep = (IPEndPoint)ep;
Console.WriteLine("Packet received from host {0}, port {1}",
iep.Address, iep.Port);

As to the performance hit, there is a lot happening under the hood
of the UdpClient class. Perhaps your two systems are powered
differently enough that the "under-the-hood" work is noticeable. I
prefer to do my coding using the Socket class because it is more
versatile, and is easier for me coming from a Unix socket background.
That said, I still think the TcpClient and UdpClient classes are great
for programmers who don't need fancy functionality (and possibly
performance?) from their network code.

Hope this helps shed some light on your problem.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471433012.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top