Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Some help needed with new threads

  1. Nov 21, 2007 #1
    I'm trying to code a game which can be played in my home server using all the computers there are. I'm trying to set up a server which takes each computer connected and makes a new thread for each to respond to. How do you do that in C#?

    Some codes as to how multiple clients can connect to a server using multiple threads will be appreciated. Thanks.
  2. jcsd
  3. Nov 21, 2007 #2
    I think what you want to do here is read up on the "Threadpool" mechanism. This allows you to dispatch tasks (such as, "start servicing this socket") and have them each be picked up by a member from a preallocated pool of threads.
  4. Nov 21, 2007 #3
    Hi, thanks, I'm researching about Threadpools now.

    Meanwhile can anyone please show me a very simple example of how to set up a server which can service multiple clients at the same time. A short example would be great and much appreciated. Please help, I've been trying to do this for a few hours now with no luck. Thanks.
  5. Nov 21, 2007 #4
    Does this help any? It's based on brief, stateless connections but sounds like it does everything you want, just that you want the connections to remain going for a long time...

    You can actually find a lot of great sample code by searching on google for ".net multithreaded server sample" or ".net server sample", this exact problem is actually a pretty common subject for .NET tutorials and I'm pretty sure there's even some samples on MSDN (though I can't remember where to find them).
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?