Esempio n. 1
0
  public void run() {
    String clientString;
    String serverString;
    ServerSocket socket = null;

    try {
      System.out.println("SERVER: Initializing server socket");
      socket = new ServerSocket(5000);
      System.out.printf("SERVER: Server socket initialized %s\n", socket.toString());
      while (true) {
        System.out.println("SERVER: Connecting to socket port 5000");
        Socket connectionSocket = socket.accept();
        System.out.printf("SERVER: Connected to socket %s\n", connectionSocket.toString());
        BufferedReader inFromClient =
            new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
        DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
        System.out.println("SERVER: Reading from socket");
        clientString = inFromClient.readLine() + "\n";
        ServerData.clientCommand = clientString;
        if (ServerData.state.equals(ServerData.State.NEGOTIATING)) {
          serverString = negotiate();
          ServerData.state = ServerData.State.STREAMING;
          outToClient.writeBytes(serverString + "\n");
          ServerData.mainThread.interrupt();
        } else if (ServerData.state.equals(ServerData.State.STREAMING)) {
          adaptPipeline();
          serverString = "State change successful";
          outToClient.writeBytes(serverString + "\n");
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 /** @tests java.net.ServerSocket#toString() */
 public void test_toString() throws Exception {
   s = new ServerSocket(0);
   try {
     int portNumber = s.getLocalPort();
     assertEquals(
         "ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=" + portNumber + "]", s.toString());
   } finally {
     s.close();
   }
 }
Esempio n. 3
0
 /**
  * The NetLoadableServer interface requires a method that will return a representation of the
  * current server state. This server's state is its network location (IP:port).
  */
 @Override
 public String dumpState() {
   StringBuilder sb = new StringBuilder(super.dumpState());
   sb.append("\nListening on:\n\tTCP: ");
   if (mServerSocket != null) sb.append(mServerSocket.toString());
   else sb.append("Not listening");
   sb.append("\n\tUDP: ");
   if (mDatagramSocket != null) sb.append(mDatagramSocket.getLocalSocketAddress());
   else sb.append("Not listening");
   return sb.toString();
 }
 public String toString() {
   return serverSocket.toString();
 }