 <p>The important bit in the Oracle article you mention is the part titled - <strong>Supporting Multiple Clients</strong>.</p> <p>The basic Java socket API is a blocking API, which basically means you call a method and that method blocks until an IO event happens. If you need to wait for multiple IO events - in your case an incoming client connection and incoming data - you have to create multiple threads.</p> <p>The server shown in the article only accepts a single incomming (client) connection and will close once the client closes because the <code>InputStream</code> on the server will return <code>null</code> causing the loop to terminate.</p> <p>First your server needs to look something like this (which is simplified example):</p> <pre><code>try (ServerSocket serverSocket = new ServerSocket(portNumber)) { while (running) { Socket clientSocket = serverSocket.accept(); new Thread(new ClientHandler(clientSocket)).start(); } } </code></pre> <p><strong>Note:</strong> starting a thread for each client connection demonstrates the point but is a vast over simplification of managing the connection load on a server.</p> <p>The client code can remain as is.</p> <p>That's the basics that as I pointed out leaves the thread management in the developers hands - this often leads to trouble because people simply get it wrong. Because of this Java's socket APIs have been extended to create the <a href="http://en.wikipedia.org/wiki/Non-blocking_I/O_(Java)" rel="nofollow">NIO</a> API - Jakob Jenkov has written some good <a href="http://tutorials.jenkov.com/java-nio/index.html" rel="nofollow">tutorials</a>.</p> <p>It's also worth looking at <a href="http://netty.io/" rel="nofollow">Netty</a>, which personally I think is easier to use than <a href="http://en.wikipedia.org/wiki/Non-blocking_I/O_(Java)" rel="nofollow">NIO</a>.</p>