I want status update from the devices which communicate on udp, every minute. what method i should use. Any kind of suggestions will be appreciated. Thanks
What I have tried:
I have tried this
foreach (IPAddress ips in iPAddresses)
{
Byte[] receiveBytes = { };
Byte[] dataToSend = new Byte[] { 0x8B, 0xB9, 0x00, 0x03, 0x05, 0x01, 0x09 };
IPEndPoint endPoint = new IPEndPoint(ips, 1024);
EndPoint ep = (EndPoint)endPoint;
Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try
{
udpClient.Connect(endPoint);
udpClient.SendTo(dataToSend, ep);
IPEndPoint localip = new IPEndPoint(IPAddress.Any, 1200);
UdpClient receivingUdpClient = new UdpClient(localip);
receiveBytes = receivingUdpClient.Receive(ref endPoint);
udpClient.Close();
receivingUdpClient.Close();
receivingUdpClient.Dispose();
updateData(receiveBytes, ips);
}
finally
{
udpClient.Dispose();
}
}
The problem I can find is through this line-
receiveBytes = receivingUdpClient.Receive(ref endPoint);
ref endpoint in receive() is having 1st ip address only. its not changing. Send method is able to change ip address. but not receive method.
I have tried some other methods too before this. but this is what I am doing now