I made a script that sends and receives udp broadcasts between two PCs. Its the same script on both PCs. PC A can see packets from PC B, but it doesn’t work the other way around. I checked with wireshark on PC B and can see the packets from A arriving, they just don’t register in unity. Does anyone know what this could be?
This is the listening part of my code. PC B does get into the listenCallback but the ar.endpoint = 0.0.0.0 instead of the ip address of A and the execution stops (without an error thrown) at the receivedBytes line.
private static void listen() {
if (udpClient != null) udpClient.Close();
Debug.Log("Listen!");
IPEndPoint ep1 = new IPEndPoint(IPAddress.Any, port);
UdpClient uc1 = new UdpClient(ep1);
UdpState us1 = new UdpState();
us1.e = ep1;
us1.u = uc1;
uc1.BeginReceive(new AsyncCallback(listenCallback), us1);
udpClient = uc1;
}
private static void listenCallback(IAsyncResult ar) {
UdpClient uc1 = ((UdpState)(ar.AsyncState)).u;
IPEndPoint ep1 = ((UdpState)(ar.AsyncState)).e;
byte[] receivedBytes = uc1.EndReceive(ar, ref ep1);
Debug.Log("Received something");
uc1.Close();
string ip = ep1.Address.ToString();
NetworkResident r = residents.Find(i => i.ip == ip);
if (r != null)
r.lastSeen = DateTime.Now.Ticks;
else {
r = new NetworkResident(ep1.Address, receivedBytes);
residents.Add(r);
onNewResident();
}
}