Note that there are some explanatory texts on larger screens.

plurals
  1. POCommunication between client and server got some glitches
    primarykey
    data
    text
    <p>I got here client and server side programs. Client talks to server by sending a string, the server then converts the string into capital letters and sends back. The problem is that the client does not receive any string from the server. Only the server prints 2 passed in strings, then the server throws IOException. I guess that because client closed connection. But why does client does not receive any message from server? How to overcome this issue? Thanks</p> <pre><code>Client: package solutions; import java.io.*; import java.net.*; class SocketExampleClient { public static void main(String [] args) throws Exception { String host = "localhost"; // hostname of server int port = 5678; // port of server Socket s = new Socket(host, port); DataOutputStream dos = new DataOutputStream(s.getOutputStream()); DataInputStream dis = new DataInputStream(s.getInputStream()); dos.writeUTF("Hello World!"); System.out.println(dis.readUTF()); dos.writeUTF("Happy new year!"); System.out.println(dis.readUTF()); dos.writeUTF("What's the problem?!"); System.out.println(dis.readUTF()); } } </code></pre> <p>Server:</p> <pre><code>package solutions; import java.io.*; import java.net.*; class SocketExampleServer { public static void main(String [] args) throws Exception { int port = 5678; ServerSocket ss = new ServerSocket(port); System.out.println("Waiting incoming connection..."); Socket s = ss.accept(); DataInputStream dis = new DataInputStream(s.getInputStream()); DataOutputStream dos = new DataOutputStream(s.getOutputStream()); String x = null; try { while ((x = dis.readUTF()) != null) { System.out.println(x); dos.writeUTF(x.toUpperCase()); } } catch(IOException e) { System.err.println("Client closed its connection."); } } } </code></pre> <p>Output:</p> <pre><code>Waiting incoming connection... Hello World! Happy new year! What's the problem?! Client closed its connection. </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