我有这个客户端代码
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);
}
}
}
我想知道我是如何检查客户端是否接收到某些东西或者没有,来自服务器,因为我想要但是如果客户端没有收到任何东西它意味着PKT丢失,则计时器为30ms!