F
Fred Palmer
I am trying to get reponses from multiple devices on my network by sending the
following message via UDP:
// Create the message
Byte[] bytesSent = new Byte [] {0x00, 0x00, 0x00, 0xF6};
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
// Send the message to be broadcast
s.SendTo(bytesSent, bytesSent.Length, 0, new
IPEndPoint(IPAddress.Parse("192.168.1.255"), 30718));
IPEndPoint senderEndPoint = new IPEndPoint(IPAddress.Any, 0);
EndPoint senderRemote = (EndPoint)senderEndPoint;
byte[] msg = new Byte[256];
// Gets the message from the first device to respond.
s.ReceiveFrom(msg, 0, msg.Length, SocketFlags.None, ref senderRemote);
textBox1.AppendText(senderRemote.ToString() + "\r\n");
s.Close();
Currently this works, but how do I get messages from multiple devices on my
network? The message gets to all of them and they all send a response, but I
just can't figure out how to process them. Essentially all of these devices are
returning an acknowledgement that they exist, so I just need to get their IP
address as in the example.
Thanks,
Fred
following message via UDP:
// Create the message
Byte[] bytesSent = new Byte [] {0x00, 0x00, 0x00, 0xF6};
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
// Send the message to be broadcast
s.SendTo(bytesSent, bytesSent.Length, 0, new
IPEndPoint(IPAddress.Parse("192.168.1.255"), 30718));
IPEndPoint senderEndPoint = new IPEndPoint(IPAddress.Any, 0);
EndPoint senderRemote = (EndPoint)senderEndPoint;
byte[] msg = new Byte[256];
// Gets the message from the first device to respond.
s.ReceiveFrom(msg, 0, msg.Length, SocketFlags.None, ref senderRemote);
textBox1.AppendText(senderRemote.ToString() + "\r\n");
s.Close();
Currently this works, but how do I get messages from multiple devices on my
network? The message gets to all of them and they all send a response, but I
just can't figure out how to process them. Essentially all of these devices are
returning an acknowledgement that they exist, so I just need to get their IP
address as in the example.
Thanks,
Fred