I have a simple UDP Client pointing to 127.0.0.1:15000
and I have a Provider who sends me information through UDP and he says, he broadcasts the signals through the network and that he does not know what clients are listening and that I should be able to receive the signals if I point to the correct port. I know this sounds a little confusing, but what is wrong here? Is my provider wrong or I am not listening correctly to the broadcast?
private int port;
private UdpClient udp;
public UdpReceiver(int port)
{
this.port = port;
udp = new UdpClient(port);
StartListening();
}
private void StartListening()
{
this.udp.BeginReceive(Receive, new object());
}
private void Receive(IAsyncResult ar)
{
if (udp != null)
{
IPEndPoint ip = new IPEndPoint(IPAddress.Any, port);
byte[] bytes = udp != null ? udp.EndReceive(ar, ref ip) : null;
if (bytes != null)
{
string message = Encoding.ASCII.GetString(bytes);
MessageBox.Show(message);
StartListening();
}
}
}