private boolean sendComplete = true;
byte[] sendData = new byte[1];
byte[] receiveData = {0,0};
public class Client implements Runnable {
@Override
public void run() {
sendComplete = false;
DatagramSocket clientSocket = null;
try {
InetAddress serverAddr = InetAddress.getByName(SERVERIP);
clientSocket = new DatagramSocket();
clientSocket.setSoTimeout(1000);
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, serverAddr, SERVERPORT);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
} catch (Exception e) {
e.printStackTrace();
receiveData[0]=0;
receiveData[1]=0;
} finally {
if (clientSocket != null) {
clientSocket.close();
}
sendComplete = true;
}
}
}