|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
do { |
|
|
do { |
|
|
byte[] receiveData = new byte[512]; |
|
|
byte[] receiveData = new byte[512]; |
|
|
InetAddress fromAdress; |
|
|
|
|
|
int fromPort; |
|
|
|
|
|
DatagramPacket rxPacket = new DatagramPacket(receiveData, receiveData.length); |
|
|
DatagramPacket rxPacket = new DatagramPacket(receiveData, receiveData.length); |
|
|
socket.receive(rxPacket); |
|
|
socket.receive(rxPacket); |
|
|
fromAdress = rxPacket.getAddress(); |
|
|
|
|
|
fromPort = rxPacket.getPort(); |
|
|
|
|
|
rxString = new String(rxPacket.getData()); |
|
|
rxString = new String(rxPacket.getData()); |
|
|
if(!previousRxString.equals(rxString)) { |
|
|
if(!previousRxString.equals(rxString)) { |
|
|
rxStringBuffer.append(rxString).append("\n"); |
|
|
rxStringBuffer.append(rxString).append("\n"); |
|
|
mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer)); |
|
|
mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer)); |
|
|
previousRxString = rxString; |
|
|
previousRxString = rxString; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} while (running); |
|
|
} while (running); |
|
|
} |
|
|
} |
|
|
catch (IOException e) { |
|
|
catch (IOException e) { |