Note that there are some explanatory texts on larger screens.

plurals
  1. POServer accept socket but after that the socket cannot receive anything
    primarykey
    data
    text
    <p>I've encountered a very strange problem (since this always worked before) when building a client-server chat program. </p> <p>The serversocket accepts without any problem the incoming connection of the client, but when I try to read from the socket's inputstream the whole method blocks and only releases when I close the client's socket.</p> <p>I've even tried it with the sample code on docs.oracle.com, but the problem remains.</p> <p>Can anybody point me out the error I'm obviously not seeing?</p> <p>Server code:</p> <pre><code>public class Server { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { System.out.println("Creating server socket"); ServerSocket internetSocket = new ServerSocket(60000); if(!internetSocket.isClosed()) { while(true) { Socket s = internetSocket.accept(); System.out.println("accepted socket!"); BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while((line = reader.readLine()) != null) { System.out.println(line); } } } } } </code></pre> <p>Client code:</p> <pre><code>public class Client { public static void main(String[] args) throws IOException { Socket s = null; try { s = new Socket("localhost", 60000); } catch (UnknownHostException ex) { Logger.getLogger(Start2.class.getName()).log(Level.SEVERE, null, ex); } PrintWriter outStream = new PrintWriter(s.getOutputStream()); for(int i=0; i&lt;10; i++) { outStream.println("test"); System.out.println("Sending the message \"test\""); try { Thread.sleep(5000); } catch (InterruptedException ex) { Logger.getLogger(Start2.class.getName()).log(Level.SEVERE, null, ex); } } s.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload