Skip to content

Instantly share code, notes, and snippets.

@aztechdev
Created November 23, 2016 09:32
Show Gist options
  • Save aztechdev/2ea809febe17be689a8b70d55daf507b to your computer and use it in GitHub Desktop.
Save aztechdev/2ea809febe17be689a8b70d55daf507b to your computer and use it in GitHub Desktop.
Server Piece of ROBOdyssey Gesture Controller
import java.io.DataInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.InetAddress;
public class GestureReceiver {
private ServerSocket serverSocket;
private DataInputStream input;
//Thread serverThread = null;
public static final int SERVERPORT = 8888;
public static void main(String[] args){
//this.serverThread = new Thread(new ServerThread());
//this.serverThread.start();
ServerThread serverThread = (new GestureReceiver().new ServerThread());
new Thread(serverThread).start();
}
class ServerThread implements Runnable {
public void run() {
Socket clientSocket = null;
try {
serverSocket = new ServerSocket(SERVERPORT);
System.out.println("Listening on :" + SERVERPORT);
} catch(IOException e){
e.printStackTrace();
}
while(!Thread.currentThread().isInterrupted()){
try {
System.out.println("Waiting for client connection...");
clientSocket = serverSocket.accept();
input = new DataInputStream(clientSocket.getInputStream());
System.out.println("ip: " + clientSocket.getInetAddress());
System.out.println("message: " + input.readUTF());
} catch(IOException e){
e.printStackTrace();
}
}
}
//clientSocket.close();
//serverSocket.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment