Jump to content
  • Advertisement
Sign in to follow this  
robert_p

Simple begginer question

This topic is 4887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I starting playing with sockets about 2 days ago and have some crappy hello world client/server code. I was about to make it support multiple clients but one thing bothers me a little. I was going to do 2 threads 1 for the accept and one for all the logged in clients, but I notice that every example I've looked at uses a thread for each client(I mean every single one). Am i just missing something here. It dosent seem like a bad method or anything but I'd like to avoid alot of threads everywhere.

Share this post


Link to post
Share on other sites
Advertisement
I believe you do need a child process for each client. I programmed some client server software in Linux and we had to fork() a new child process for every client that connected.

This is obviously necessary because you can't handle all the threads in one exe.

Anyone care to wrap this up?

ace

Share this post


Link to post
Share on other sites
You don't need a separate thread for each client, however that's the easiest way of doing it. You can use the select() function to check if there is data waiting to be received or if there is a client connecting, and only call the blocking functions when they are needed. You can read more at this site. The site is aimed at winsock, but it works the same way in other operating systems using sockets. You should especially take a look at the section about the "select()-based Server". It comes with source code too so it shouldn't be to hard to understand.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!