Kommunikation Version 1.2 UDP Socket
This commit is contained in:
parent
b246ad8624
commit
e89a5d11a1
@ -28,8 +28,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
WifiCommunication communication;
|
WifiCommunication communication;
|
||||||
public static String SERVER_IP = "";
|
public static String SERVER_IP = "";
|
||||||
public static final int SERVER_PORT = 2222;
|
public static final int SERVER_PORT = 1234;
|
||||||
int i=0;
|
float i=0;
|
||||||
|
|
||||||
boolean sending = false;
|
boolean sending = false;
|
||||||
|
|
||||||
@ -55,14 +55,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
i++;
|
i++;
|
||||||
communication.sendTrue(deviceId+ "Test" +i);
|
communication.sendTrue(String.valueOf(i));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
communication = new WifiCommunication(MainActivity.this, SERVER_PORT);
|
communication = new WifiCommunication(MainActivity.this, SERVER_PORT);
|
||||||
//communication.sendTrue(deviceId+ " has Entered");
|
//communication.sendTrue(" has Entered ");
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,6 +9,8 @@ import java.net.InetAddress;
|
|||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
public class WifiCommunication {
|
public class WifiCommunication {
|
||||||
@ -27,7 +29,7 @@ public class WifiCommunication {
|
|||||||
try {
|
try {
|
||||||
socket = new DatagramSocket(this.port);
|
socket = new DatagramSocket(this.port);
|
||||||
socket.setBroadcast(true);
|
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;
|
running = true;
|
||||||
send = false;
|
send = false;
|
||||||
new ReceiveThread().start();
|
new ReceiveThread().start();
|
||||||
@ -77,8 +79,11 @@ public class WifiCommunication {
|
|||||||
if(send)
|
if(send)
|
||||||
{
|
{
|
||||||
send = false;
|
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];
|
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();
|
send_Data = txString.getBytes();
|
||||||
|
|
||||||
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);
|
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user