I have a UDP Server and client which works on localhost when the server and client are both behind the same router.
When connecting from external IP - the IPEndPoint holds the server IP.
Server receiver:
private void Recv(IAsyncResult res)
{
IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, 0);
try
{
byte[] data = udpClient.EndReceive(res, ref clientEndPoint);
udpClient.BeginReceive(new AsyncCallback(Recv), null);
//Process codes
RaiseDataReceived(new ReceivedDataArgs(clientEndPoint.Address, clientEndPoint.Port, data));
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw;
}
}
When the server receives a message from external client, the clientEndPoint.Address holds the server's address, not the client address. Has anyone experienced this? I've tried multiple ways of receiving messages from clients without luck.