[Tutor] should we use multithreading for multiple clients in socket class

Alan Gauld alan.gauld at btinternet.com
Thu Apr 12 18:24:12 CEST 2012

On 12/04/12 12:38, Surya K wrote:
> I am learning networking and just wrote a primitive client server program..
> So, I tried to run another client (same code but from different file)
> but found that its now working.

I assume that should be *not working*?
A more detailed description of what you did and the result would help 
diagnose the issue.

> why its happening, should I use multithreading so that I can handle two
> clients simultaneously??

It's not strictly necessary if there are no resource conflicts such as 
two attempts to write to the same file/data structure. But in the 
general case multi-threading a server (or forking a separate
process) is a good idea.

However, there is some implicit "threading" takes place in the socket 
library insofar as each session is given a separate temporary port to 
communicate over once the connection has been accepted so unless the 
connections are using conflicting resource it should still work.

See the network programming topic in my tutorial for an example and 
screenshots of two clients talking to one server...

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list