In: Computer Science
For each client connection, the server starts a child thread to process the request independent of any other incoming requests. The ServerClientThread is a new class extends Thread Class . Here you can see, rather than processing the incoming requests in the same thread that accepts the client connection, the connection is handed off to a client thread that processes the request. That way the thread listening for next incoming requests spends as much time as possible in the serverSocket.accept() call. That way the risk is minimized for clients being denied access to the server because the listening thread is not inside the accept() call. Here the client thread actually executes the request. In the meantime server can take multiple client requests and start the processing. So individual threads will be started and they will work in parallel . In this example the client send a number to the server and in response to each client, the server send back the square of the received number.