Udp server receives too much data

G

gregorj

I have a problem using udp client/server communication. After I send
some buffer to server, server always receives the buffer three times.
I doubt that this is an expected behaviour, so please someone tell me
what I'm doing wrong.

SERVER CODE
EndPoint endPoint = new IPEndPoint(IPAddress.Any, 9944);

Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
server.Bind(endPoint);
server.Poll(Timeout.Infinite, SelectMode.SelectRead);


CLIENT CODE
EndPoint endPoint = new IPEndPoint(IPAddress.Broadcast,
9944);

Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
client.EnableBroadcast = true;
client.SendTo(BitConverter.GetBytes(999), endPoint);


Thx!
 
P

Peter Duniho

I have a problem using udp client/server communication. After I send
some buffer to server, server always receives the buffer three times.
I doubt that this is an expected behaviour, so please someone tell me
what I'm doing wrong.

I wouldn't say it's normal, but neither is it completely unexpected. UDP
does not guarantee that you will receive a datagram only once even when
sent directly. You're broadcasting, which opens up possibilities for the
datagram to travel multiple routes and be received multiple times. For
example, you don't happen to be testing this code on a single PC, that
happens to have three network adapters installed (maybe a wireless, a
wired, and a 1394 adapter, for example)?

Pete
 

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