Code example for ServerSocket

Methods: accept

0
    intPattern = Pattern.compile("[0-9-][0-9]*");
    floatPattern = Pattern.compile("[0-9-][0-9]*\\.[0-9]*");
 
    try { 
      // Open a socket to listen on. 
      ServerSocket serverSocket = new ServerSocket(SERVER_PORT);
      System.out.println("Socket started on port " + SERVER_PORT);
 
      // Wait (blocking) for an incoming connection 
      socket = serverSocket.accept();
      System.out.println("Client connected");
 
      // Setup the streams 
      out = new PrintStream(socket.getOutputStream(), true);
      in =
          new BufferedReader(new InputStreamReader(socket.getInputStream(),
              "UTF8")); 
    } catch (IOException e) {
      // Something went wrong and we were unable to set up a connection. This is 
      // pretty 
      // much a fatal error.