0

i have udp socket that send 100 string every 1 seconds and when data Received i want to check the data is right or not and measure data packet loss

source to send string :

string toSend;
byte[] data = Encoding.ASCII.GetBytes(toSend);

as i know udp can't check the data is right or not and can't measure packet loss, except the Received already know the data will Receive

so for statistic i send data that Receiver already know every 5 second

how do i know the data was send is right or packet loss when data Receive ?

iboy15
  • 35
  • 1
  • 9

1 Answers1

1

Add your own protocol om top of UDP, a protocol which includes some kind of sequence number. If you start the sequence number from zero, and send six packets then the last packet should have sequence number five.If you receive packets with sequence numbers 0, 1 and 5 then you know that you have a 50% packet loss for those six packets.

For error checking, add a simple checksum for each packet.


Also if you want better reliability, then with the sequence numbering scheme can easily implement packet reordering so packets that arrive in the wrong order are rearranged to be in the correct order. It's also easy to implement acknowledgements and retransmission of lost packets. So adding this on top of UDP is a way of implementing a very simple TCP-like protocol. Many protocols that uses UDP implement some or all of these things.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621