|
|
|
|
|
|
|
|
volatile private boolean running; |
|
|
volatile private boolean running; |
|
|
|
|
|
|
|
|
private boolean Gruppe =true; |
|
|
private boolean Gruppe =true; |
|
|
|
|
|
private boolean showMessage = true; |
|
|
|
|
|
|
|
|
|
|
|
StringBuffer rxStringBuffer = new StringBuffer(); |
|
|
|
|
|
|
|
|
private OnConnectionListener listener; |
|
|
private OnConnectionListener listener; |
|
|
@SuppressLint("SetTextI18n") |
|
|
@SuppressLint("SetTextI18n") |
|
|
|
|
|
|
|
|
socket.receive(rxPacket); |
|
|
socket.receive(rxPacket); |
|
|
rxString = new String(receiveData, 0, rxPacket.getLength()); |
|
|
rxString = new String(receiveData, 0, rxPacket.getLength()); |
|
|
String[] splitrxString = rxString.split(","); |
|
|
String[] splitrxString = rxString.split(","); |
|
|
|
|
|
String[] splitrxStringBuffer = splitBufferIntoStrings(rxStringBuffer); |
|
|
|
|
|
for(String elem: splitrxStringBuffer){ |
|
|
|
|
|
if(elem.equals(rxString)){ |
|
|
|
|
|
showMessage = false; |
|
|
|
|
|
}else{ |
|
|
|
|
|
showMessage = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
if(Gruppe){ |
|
|
if(Gruppe){ |
|
|
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) { |
|
|
|
|
|
//rxStringBuffer.append(rxString).append("\n"); |
|
|
|
|
|
|
|
|
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7 && showMessage) { |
|
|
|
|
|
rxStringBuffer.append(rxString).append("\n"); |
|
|
|
|
|
Log.d("empfangen", rxString); |
|
|
|
|
|
sendWifiData(rxString); |
|
|
|
|
|
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer)); |
|
|
|
|
|
previousRxString = rxString; |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7 && showMessage) { |
|
|
|
|
|
rxStringBuffer.append(rxString).append("\n"); |
|
|
Log.d("empfangen", rxString); |
|
|
Log.d("empfangen", rxString); |
|
|
sendWifiData(rxString); |
|
|
sendWifiData(rxString); |
|
|
//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) { |
|
|
|
|
|
|
|
|
if(send) |
|
|
if(send) |
|
|
{ |
|
|
{ |
|
|
send = false; |
|
|
send = false; |
|
|
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); |
|
|
|
|
|
|
|
|
/*SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); |
|
|
Date curDate = new Date(System.currentTimeMillis()); |
|
|
Date curDate = new Date(System.currentTimeMillis()); |
|
|
String str = formatter.format(curDate); |
|
|
|
|
|
|
|
|
String str = formatter.format(curDate);*/ |
|
|
byte[] send_Data = new byte[512]; |
|
|
byte[] send_Data = new byte[512]; |
|
|
String txString = (messageToSend); //"1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," |
|
|
String txString = (messageToSend); //"1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," |
|
|
Log.d("send", txString); |
|
|
Log.d("send", txString); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port); |
|
|
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port); |
|
|
|
|
|
|
|
|
for(int i = 0; i < 300; i++) { |
|
|
|
|
|
|
|
|
for(int i = 0; i < 500; i++) { |
|
|
socket.send(txPacket); |
|
|
socket.send(txPacket); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
running = false; |
|
|
running = false; |
|
|
socket.close(); |
|
|
socket.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
public String[] splitBufferIntoStrings(StringBuffer string){ |
|
|
|
|
|
String[] splitrxString2 = string.toString().split("\n"); |
|
|
|
|
|
return splitrxString2; |
|
|
|
|
|
} |
|
|
} |
|
|
} |