public class server {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
String clientCommand, capitalizedSentence;
Integer port = 0;
port = Integer.parseInt(args[0]);
try {
serverSocket = new ServerSocket(port); //1234
} catch (IOException e) {
System.err.println("Could not listen on port: 1234.");
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
System.err.println("Accept failed.");
System.exit(1);
}
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(clientSocket.getOutputStream());
clientCommand = inFromClient.readLine();
System.out.println("The Command is: " + clientCommand); // The correct command is printed.
Process runCommand = Runtime.getRuntime().exec(clientCommand);
outToClient.close();
inFromClient.close();
clientSocket.close();
serverSocket.close();
}
}