Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multithreading with clients and servers  RSS feed

 
Jake Jameson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code





How can I extend/modify the given server code so that the server is able to interact with multiple clients in parallel (concurrently), using multithreading.

The number of clients simultaneously connected to the same server should not be restricted.

The given client code doesn't need to be modified. The client code should be able to start as many clients as one would like at about the same time (they should start directly one after another so they will run in parallel for most of the time).

I'm new to this and am having great difficulty understanding it so if anyone could show me how to do this, that would be great.

Thanks in advance
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the code you have posted isn't multi-threaded because it doesn't create any threads. So either your server is going to have to create a new thread each time it receives an incoming connection, or it will need to use a thread pool to manage the threads for it.

These oracle tutorials will help you:

1) Using Threads
2) Using Executors to manage threads

Note that the second link is actually a sub-section of the first one, so they are effectively the same tutorial. The first link starts from the beginning, and the second one jumps straight to Executors.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!