tags:

views:

172

answers:

1

In order to receive datagrams through an UDP connection I have created an object of type UDPClient.

 receivedNotificationSock = new UdpClient();

However once done and on using the receive method:

 receivedHostNameBuffer=receivedNotificationSock.Receive(ref receivedNotificationIP);

I am getting an exception saying that I must call the bind method. But there is no bind method in the UDPClient class. Could You guys please provide me with the code if possible as to what should be done to overcome this exception.

+1  A: 

You need I think to know some more about sockets.

All sockets possess a port number. First, you create a socket - which is almost useless on its own. It just floats there. But then you bind it - you assign it a port number. Now it's useful - now you can send and receive data on it.

Remember, all UDP communications are defined by the quad data set of the IP and port of the source and the IP and port of the destination. A freshly created socket doesn't have an IP address or port; binding gives it an IP address and port.

Unfortunately, I'm not a C# programmer, so I can't properly answer your question. But at least you know why it's important.

Blank Xavier
i am getting binding error while using udp connection... please help me as what can be done
saurabh