.......After spending so many hours on this issue, I finally figure out what the problem is.
IPAddress serverIP = IPAddress.Parse("xx.xx.xx.xx");
IPEndPoint serverEP = new IPEndPoint(serverIP, 12345);
UdpClient client = new UdpClient();
//start listening
client.BeginReceive(new AsyncCallback(ReceiveCallback), serverEP); //here causes the problem
//send message to server and wait for response
client.Send(Encoding.UTF8.GetBytes("Hello"), "Hello".Length, serverEP);
.....
The error message already mentioned that you must Bind first! Therefore, I changed the order of the listening & sending, and it works! Here is the code that works
.......This may not be the case that you encounter. It just one of the many possibilities to solve the issue.
IPAddress serverIP = IPAddress.Parse("xx.xx.xx.xx");
IPEndPoint serverEP = new IPEndPoint(serverIP, 12345);
UdpClient client = new UdpClient();
//send message to server and wait for response
client.Send(Encoding.UTF8.GetBytes("Hello"), "Hello".Length, serverEP);
//start listening
client.BeginReceive(new AsyncCallback(ReceiveCallback), serverEP);
.....
You are absolutely right
ReplyDeleteplease post VB.NET Code.
ReplyDeleteYou can try the "Convert C# to VB.Net" link from my External Links section at the bottom right corner.
ReplyDeleteThanks for Solution but this not work in .NET Framework 3.5 .
ReplyDeleteIn my Application, "You must call the Bind method before performing this operation." error generated how it solve???
please give me a solution.
?????? where is solution? ????????
ReplyDeleteIf this doesn't resolve your problem, you probably have to Google it for other solutions.
ReplyDeleteThe correct solution is documented here:
ReplyDeletehttp://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.aspx
You must use the constructor that accepts (int)port on the UDPClient that is receiving the message.