Note that there are some explanatory texts on larger screens.

plurals
  1. POServer/client communication
    primarykey
    data
    text
    <p>I got a program which listens to connections from a client.</p> <pre><code>import java.io.*; import java.net.*; class SocketExampleServer { public static void main(String [] args) throws Exception { int port = 5665; ServerSocket ss = new ServerSocket(port); System.out.println("Waiting incoming connection..."); Socket s = ss.accept(); DataInputStream dis = new DataInputStream(s.getInputStream()); DataOutputStream out = new DataOutputStream(s.getOutputStream()); String x = null; try { while ((x = dis.readUTF()) != null) { System.out.println(x); out.writeUTF(x.toUpperCase()); } } catch(IOException e) { System.err.println("Client closed its connection."); } catch(Exception e) { System.err.println("Unknown exception"); } s.close(); ss.close(); dis.close(); out.close(); System.exit(0); } } </code></pre> <p>The things is that at this point </p> <pre><code> System.out.println(x); out.writeUTF(x.toUpperCase()); </code></pre> <p>only the second line is executed. If you swap the line once a gain only the second line is executed. What is the reason for that? And one more thing when I run the program second time it throws this error:</p> <pre><code>Exception in thread "main" java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.PlainSocketImpl.bind(Unknown Source) at java.net.ServerSocket.bind(Unknown Source) at java.net.ServerSocket.&lt;init&gt;(Unknown Source) at java.net.ServerSocket.&lt;init&gt;(Unknown Source) at SocketExampleServer.main(SocketExampleServer.java:9) </code></pre> <p>Once I change the port number to a new one it runs for a one time and the next time you need to update the port number if you want to run it again. I did not get the reason for that cause I close the socket and in my opinion the port shall stay free for the next run up.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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