Code example for ServerSocket

Methods: accept

    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(),
    } catch (IOException e) {
      // Something went wrong and we were unable to set up a connection. This is 
      // pretty 
Experience pair programming with AI  Get Codota for Java