I have c# executables called server, client and client2 messaging each other on the same addr. I am differentiating the msgs by port number at which they are coming.
regular run-1
Server starts
client joins, leaves
run-2
server starts
client 2 joins, leaves
run-3
server starts
client joins
client2 joins (here comes the problem), sometimes it gets the reply from server, sometimes it just hangs and the reply from server doesnt reach.
I am using the UDPClient blocking msg transfer routines.
current solution: I am sending the same msg from server twice(in hope of atleast getting the second time around), as it is very important, and I am no longer losing this msg. What can be potential downfall of such a temporary hack?
Also please tell me if my q? is incomplete I ll provide more details.
UDP itself is unreliable. You can write your own code to make it reliable for your needs, however it’s up to you to do that. If you want a reliable stream, use TCP.
Sending a UDP packet twice may reduce problems with packet loss, however you have no guarantee. I suggest you implement some acknowledgement system where the clients send a packet back to the server when they’ve successfully processed an incoming packet. The server repeatedly sends the original packet until it sees the acknowledgement. (You should still have some limit on this, otherwise it’ll try forever)
A situation where UDP is useful is where you don’t mind the occasional lost packet, but need the reduced latency that UDP can bring (as there are no built-in re-transmits). For instance state information for games, where the server sends game data via UDP. If a client doesn’t receive a packet, it’ll catch up when the next one arrives in a few milliseconds.