Android app updated (now the Android app acts even as client using the
device's accelerometers).
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Daniele Verducci
|
||||
This file is part of ExplorerBot.
|
||||
|
||||
ExplorerBot is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ExplorerBot is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ExplorerBot. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package it.danieleverducci.explorerbot;
|
||||
|
||||
public class AppConfiguration {
|
||||
public static final int PORT=6787; //Server default port
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Daniele Verducci
|
||||
This file is part of ExplorerBot.
|
||||
|
||||
ExplorerBot is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ExplorerBot is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ExplorerBot. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package it.danieleverducci.explorerbot.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import it.danieleverducci.explorerbot.AppConfiguration;
|
||||
import it.danieleverducci.explorerbot.objects.GamepadPosition;
|
||||
|
||||
public class ClientNetworkCommunicationThread extends Thread {
|
||||
|
||||
private String ipAddress;
|
||||
private boolean mustExit=false;
|
||||
private GamepadPosition lastKnownPosition;
|
||||
|
||||
public ClientNetworkCommunicationThread(String ipAddress) {
|
||||
super();
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//Setup connection
|
||||
Socket socket = new Socket(ipAddress, AppConfiguration.PORT);
|
||||
OutputStream os = socket.getOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
|
||||
//Send gamepad position every 100msec
|
||||
while(!mustExit){
|
||||
if(lastKnownPosition!=null){
|
||||
//Send to network
|
||||
try{
|
||||
oos.writeObject(lastKnownPosition);
|
||||
lastKnownPosition=null;
|
||||
}catch(SocketException e){
|
||||
System.out.println("Connection interrupted by server. Exiting.");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
//Wait 100ms
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
socket.close();
|
||||
|
||||
} catch (UnknownHostException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set @param mustExit to true to make the thread shutdown
|
||||
*/
|
||||
public void setMustExit(boolean mustExit) {
|
||||
this.mustExit = mustExit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the last gamepad's known position
|
||||
*/
|
||||
public GamepadPosition getLastKnownPosition() {
|
||||
return lastKnownPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the @param lastKnownPosition to be sent to the server
|
||||
*/
|
||||
public void setLastKnownPosition(GamepadPosition lastKnownPosition) {
|
||||
this.lastKnownPosition = lastKnownPosition;
|
||||
}
|
||||
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Daniele Verducci
|
||||
This file is part of ExplorerBot.
|
||||
|
||||
ExplorerBot is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ExplorerBot is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ExplorerBot. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package it.danieleverducci.explorerbot.interfaces;
|
||||
|
||||
import it.danieleverducci.explorerbot.objects.GamepadPosition;
|
||||
|
||||
public interface OnControllerPolledListener {
|
||||
|
||||
public void onControllerPolled(GamepadPosition position);
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Daniele Verducci
|
||||
This file is part of ExplorerBot.
|
||||
|
||||
ExplorerBot is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ExplorerBot is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ExplorerBot. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package it.danieleverducci.explorerbot.objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Object representing the gamepad's analog stick position
|
||||
*/
|
||||
public class GamepadPosition implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8066726751180370259L;
|
||||
private float x;
|
||||
private float y;
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Daniele Verducci
|
||||
This file is part of ExplorerBot.
|
||||
|
||||
ExplorerBot is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ExplorerBot is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ExplorerBot. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package it.danieleverducci.explorerbot.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import it.danieleverducci.explorerbot.AppConfiguration;
|
||||
import it.danieleverducci.explorerbot.interfaces.OnControllerPolledListener;
|
||||
import it.danieleverducci.explorerbot.objects.GamepadPosition;
|
||||
|
||||
public class ServerNetworkCommunicationThread extends Thread {
|
||||
private OnControllerPolledListener listener;
|
||||
private boolean mustExit=false;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ServerSocket server = new ServerSocket(AppConfiguration.PORT);
|
||||
System.out.println("Server started on port "+AppConfiguration.PORT);
|
||||
Socket client = server.accept();
|
||||
System.out.println("Client connected");
|
||||
server.close(); //Once the client is connected, closing the server denies other clients connections
|
||||
InputStream is = client.getInputStream();
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
while(!mustExit){
|
||||
//Read object and notify new controller position (readObject will return only when there is something to read)
|
||||
GamepadPosition pos = (GamepadPosition)ois.readObject();
|
||||
listener.onControllerPolled(pos);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the @param listener to be notified about controller events received through the network
|
||||
*/
|
||||
public void setOnControllerPolledListener(OnControllerPolledListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set @param mustStop to true to make the thread shutdown
|
||||
*/
|
||||
public void setMustExit(boolean mustExit) {
|
||||
this.mustExit = mustExit;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user