// Simple code for Java, there may be other ways. /** * First, define a class that handles a single connection */ class OneClientConnection extends Thread { protected Socket fClientSocket = null; // whatever extra data structure you need to define here public OneClientConnection(Socket clientSocket) { fClientSocket = clientSocket; this.start(); } public void run() { // do your communication using fClientSocket } } /** * We need a class to handle the accept() operation, * and to start each connection. */ public class MultiClientServer extends Thread { protected int fPort; protected ServerSocket fListenSocket = null; // define all the necessary structures public MultiClientServer(int port) { if (port == 0) port = DEFAULT_PORT; fPort = port; } public void run() { // do all the necessary initializing steps about a socket ... // DO NOT FORGET EXCEPTION HANDLING while (true) { Socket clientSocket = fListenSocket.accept(); OneClientConnection occ = new OneClientConnection(clientSocket); } } }