|
|
@@ -14,7 +14,6 @@ import control.joystick.JoystickHandler;
|
|
|
public class NetworkHandler implements Runnable{
|
|
|
|
|
|
DatagramSocket udp;
|
|
|
- DatagramSocket udpsend;
|
|
|
|
|
|
String host;
|
|
|
int port;
|
|
|
@@ -28,8 +27,6 @@ public class NetworkHandler implements Runnable{
|
|
|
ButtonHandler bth;
|
|
|
JoystickHandler jth;
|
|
|
|
|
|
- InetAddress adr;
|
|
|
-
|
|
|
public NetworkHandler(String host, int port, ButtonHandler bth, JoystickHandler jth)
|
|
|
{
|
|
|
this.host = host;
|
|
|
@@ -43,19 +40,8 @@ public class NetworkHandler implements Runnable{
|
|
|
send = new byte[1024];
|
|
|
receive = new byte[1024];
|
|
|
|
|
|
- try {
|
|
|
- adr = InetAddress.getByName("192.168.1.5");
|
|
|
- } catch (UnknownHostException e1) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e1.printStackTrace();
|
|
|
- }
|
|
|
-// try {
|
|
|
-// udp = new DatagramSocket(1112);
|
|
|
-// } catch (SocketException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
- try {
|
|
|
- udpsend = new DatagramSocket();
|
|
|
+ try {
|
|
|
+ udp = new DatagramSocket(1113);
|
|
|
} catch (SocketException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -78,12 +64,7 @@ public class NetworkHandler implements Runnable{
|
|
|
|
|
|
private void send(String str)
|
|
|
{
|
|
|
- send = str.getBytes();
|
|
|
- try {
|
|
|
- udpsend.send(new DatagramPacket(send, send.length, adr, port));
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void close()
|
|
|
@@ -100,19 +81,19 @@ public class NetworkHandler implements Runnable{
|
|
|
{
|
|
|
DatagramPacket receivePacket = new DatagramPacket(receive, receive.length);
|
|
|
try {
|
|
|
- udpsend.receive(receivePacket);
|
|
|
+ udp.receive(receivePacket);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
String sentence = new String( receivePacket.getData());
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
sentence = sentence.trim();
|
|
|
+
|
|
|
String[] controls = sentence.split("\\|");
|
|
|
int[] control = new int[controls.length];
|
|
|
- for(int i=0; i<controls.length; i++){
|
|
|
+ for(int i=0; i<controls.length; i++)
|
|
|
control[i] = Integer.parseInt(controls[i]);
|
|
|
- }
|
|
|
+
|
|
|
for(int i = 0; i < 7; i++){
|
|
|
if(control[i] != ButtonHandler.getButton(i).pressed)
|
|
|
{
|
|
|
@@ -178,6 +159,9 @@ public class NetworkHandler implements Runnable{
|
|
|
JoystickHandler.j.setPosition(Position.DOWN);
|
|
|
jth.onJoystickMoved(JoystickHandler.j);
|
|
|
}
|
|
|
+ }else {
|
|
|
+ JoystickHandler.j.setPosition(Position.CENTER);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|