Boost Your C# Game Server: How to Use Multiple Threads for Enhanced Performance

  • Thread starter Thread starter CodeMonkey
  • Start date Start date
  • Tags Tags
    Threads
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 3K views
CodeMonkey
Messages
11
Reaction score
0
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.
 
Physics news on Phys.org
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.
 
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.
 
http://www.codeproject.com/dotnet/dotnettcp.asp 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).
 
Last edited by a moderator: