I can not find examples of a server socket where there is no client waiting, that is, without accept (). How can I do without executing this method and make a check on the client connection?

public void runServer() { int port = 3000; try { ServerSocket ss = new ServerSocket(port); System.out.println("Waiting for a client..."); Socket socket = ss.accept(); System.out.println("Got a client! " + socket.getInetAddress().getHostAddress()); DataInputStream in = new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); String line = null; while(true) { line = in.readUTF(); System.out.println("Input line : " + line); System.out.print("Sending back... "); out.writeUTF(line); out.flush(); System.out.println("Done!"); } } catch(Exception x) { System.out.print("Lost Connected"); } } 
  • accept is needed anyway. You can make a multi-threaded application. And already in the streams to expect customers. - Maxim Drobyshev
  • Here, I think I found what you want: stackoverflow.com/questions/4553380/… - Maxim Drobyshev
  • Without accept (), there can only be a DatagramSocket, but you cannot make a connection check with it, since there can be no connections. You can use NIO and non-blocking accept (). What exactly do you want? - Sergey Gornostaev
  • I want something in parallel with connecting clients to other processes. - MaximPixel

0