Kommunikation Version 1.2 UDP Socket

This commit is contained in:
Miguel Siebenhaar 2023-06-15 16:38:49 +02:00
parent b246ad8624
commit e89a5d11a1
2 changed files with 11 additions and 6 deletions

View File

@ -28,8 +28,8 @@ public class MainActivity extends AppCompatActivity {
WifiCommunication communication;
public static String SERVER_IP = "";
public static final int SERVER_PORT = 2222;
int i=0;
public static final int SERVER_PORT = 1234;
float i=0;
boolean sending = false;
@ -55,14 +55,14 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
i++;
communication.sendTrue(deviceId+ "Test" +i);
communication.sendTrue(String.valueOf(i));
}
});
}
protected void onResume() {
super.onResume();
communication = new WifiCommunication(MainActivity.this, SERVER_PORT);
//communication.sendTrue(deviceId+ " has Entered");
//communication.sendTrue(" has Entered ");
}
@Override

View File

@ -9,6 +9,8 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
public class WifiCommunication {
@ -27,7 +29,7 @@ public class WifiCommunication {
try {
socket = new DatagramSocket(this.port);
socket.setBroadcast(true);
address = InetAddress.getByName("10.0.2.255"); //100.82.255.255
address = InetAddress.getByName("255.255.255.255"); //100.82.255.255
running = true;
send = false;
new ReceiveThread().start();
@ -77,8 +79,11 @@ public class WifiCommunication {
if(send)
{
send = false;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());
String str = formatter.format(curDate);
byte[] send_Data = new byte[512];
String txString = (getLocalIpAddress() + " sends:" +messageToSend+ " Count: " + tmpCnt++);
String txString = (str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," +messageToSend);
send_Data = txString.getBytes();
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);