I am trying to set up a UDP communication link between 2 computers. One computer is running the client app and the other is running the server app. The client app gives the error:
You must call the Bind method before performing this operation.
Here is my code below for the client below and I have commented where the error occurs:
public delegate void ShowMessage(string message);
UdpClient udpClient = new UdpClient();
Int32 port = 11000;
public ShowMessage myDelegate;
Thread thread;
private void Form1_Load(object sender, EventArgs e)
{
thread = new Thread(new ThreadStart(ReceiveMessage));
thread.IsBackground = true;
thread.Start();
}
private void ReceiveMessage()
{
while (true)
{
IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Any, port);
//Error on this line
byte[] content = udpClient.Receive(ref remoteIPEndPoint);
if (content.Length > 0)
{
string message = Encoding.ASCII.GetString(content);
this.Invoke(myDelegate, new object[] { message });
}
}
}
Any help would be greatly appreciated.
source -> http://lamahashim.blogspot.com/2009/06/using-c-udpclient-send-and-receive.html