I have this code for client
class CCLI {
public static void main(String args[]) throws Exception
{
CCLI ccli = new CCLI() ;
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("localhost");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sentence = ccli.reversed(sentence) ;
sendData = sentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 8888);
clientSocket.send(sendPacket);
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
Thread.sleep(30);
String modifiedSentence = new String(receivePacket.getData());
if (modifiedSentence.contains(" ")){
System.out.println("Lost ");
}
else
{
System.out.println("FROM SERVER:" + modifiedSentence);
}
}
}
I want know how I check if the client received some thing or no , from server because I want but timer for 30ms if the client not received any thing it mean the PKT loss !