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"); } }