while(true){ Packet incomingPacket = connection.receive(); string[] message = incomingPacket.data; //doesn't block because packets are in a queue. if(message[0] == "0")//this means its a new user { userArrayList.Add(incomingPacket.endPoint); SendToAll(userArrayList); }}SendToAll(ArrayList users){ foreach(IPEndPoint ep in users) { connection.send("User has connected!", ep); }}connection.send(string msg, IPEndPoint ep){ socket.SendTo(getBytes(msg), ep);}
The above works if: there is no NAT or if DMZ is enabled for my computer, or there is port forwarding/triggering.
I can still send packets to the server, but not receive them otherwise.