Last active
December 17, 2015 03:29
-
-
Save jaye773/5543817 to your computer and use it in GitHub Desktop.
adb port forwarding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adb forward tcp:5001 tcp:8081 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintWriter; | |
import java.net.Socket; | |
import java.net.UnknownHostException; | |
public class Main { | |
public static void main(String[] args) { | |
new ConnectionToRaspberryPi().start(); | |
} | |
class ConnectionToRaspberryPi extends Thread { | |
public void run() { | |
Socket echoSocket = null; | |
PrintWriter out = null; | |
BufferedReader in = null; | |
String serverHostname = "localhost"; | |
try { | |
echoSocket = new Socket("localhost", 5001); | |
out = new PrintWriter(echoSocket.getOutputStream(), true); | |
in = new BufferedReader(new InputStreamReader( | |
echoSocket.getInputStream())); | |
String line = null; | |
try { | |
while ((line = in.readLine()) != null) { | |
Main.runScript(player); | |
} | |
} catch (IOException e) { | |
System.exit(0); | |
} | |
out.close(); | |
in.close(); | |
echoSocket.close(); | |
} catch (UnknownHostException e) { | |
System.err.println("Don't know about host: " + serverHostname); | |
System.exit(1); | |
} catch (IOException e) { | |
System.err.println("Couldn't get I/O for " + "the connection to: " | |
+ serverHostname); | |
System.exit(1); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import java.util.ArrayList; | |
import android.app.Application; | |
import android.os.Environment; | |
import android.util.Log; | |
import android.widget.Toast; | |
public class ServerApplication extends Application { | |
public static Socket clientSocket = null; | |
public static PrintWriter out = null; | |
public static ArrayList<Question> questions = null; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
Runnable r = new Runnable() { | |
@Override | |
public void run() { | |
ServerSocket serverSocket = null; | |
try { | |
serverSocket = new ServerSocket(8081); | |
while (true) { | |
clientSocket = serverSocket.accept(); | |
//Waiting for raspberry pi to connect to android device | |
Log.d("Connecting", "Waiting for connection....."); | |
try { | |
out = new PrintWriter( | |
clientSocket.getOutputStream(), true); | |
} catch (IOException e) { | |
Log.d("Connecting", "client did not connect"); | |
} | |
} | |
} catch (IOException e) { | |
System.err.println("Could not listen on port: 10007."); | |
System.exit(0); | |
} | |
Log.d("epics", "Connection successful"); | |
Log.d("epics", "Waiting for input....."); | |
} | |
}; | |
new Thread(r).start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment