Jump to content
  • Advertisement
Sign in to follow this  
MarkSponge

Winsock server with c++??

This topic is 4839 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 am having alot of trouble with winsock. I can't seem to get my head round the logic flow of a multithreaded server system. I have build a single client one already and have no trouble with it. When I look at examples on Google, the guys giving tutorials use there own functions and classes which is no good to me. Could someone please go through a basic multithreaded server logically. I don't even want the code, just the logic. For example: On one tutorial the server created a socket to listen on, which looped through a server function. When a client connected a new socket was created and somehow passed to a client function which it began looped through, responding depending on the data recieved, this is where i get really confused, how can two functions of code be executing at the same time??? I could copy it but I believe that there is more to programming then pressing Ctrl+C and Ctrl+V lots of times so I really want to understand this stuff. I am new to c++ (6 months), but am an experienced web programmer (PHP, javascript, XML, MySQL) and am picking up c++ quickly, this is the toughest thing so far!! Thanks in advance. Mark

Share this post


Link to post
Share on other sites
Advertisement
In order to have the server code running along with all of the client connection code, you'll need to use threads, or some other complex form of multitasking that probably isn't worth it.

Share this post


Link to post
Share on other sites
First of all, I would ask why you want specifically to be multi-threaded?

You can service multiple clients in a processor efficient way without all the overhead (and headache) of multi-threaded programming. If you're new to Windows programming you might want to start simpler.

By using asynchronous sockets and the message subsystem (check out WSAAsyncSelect) you can quite easily manage multiple clients.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gorax
In order to have the server code running along with all of the client connection code, you'll need to use threads, or some other complex form of multitasking that probably isn't worth it.


I totally disagree with you. I would put everything in one thread and I don't think it's that complex.

Share this post


Link to post
Share on other sites
Quote:
Original post by MarkSponge
I can't seem to get my head round the logic flow of a multithreaded server

how can two functions of code be executing at the same time???


Your problem seems to be with understanding multi-threading, rather than with understanding WinSock.

Multi-threading is when the control flow of a process splits into multiple threads of execution. If you have two CPUs, both threads will run at the same time; if you have a single CPU, the pre-emptive schedule will periodically (evern N milliseconds, say) interrupt one thread and re-schedule the other thread, so they take turns running.

Multi-threading means you can get higher performance out of compute-bound processes on multi-CPU systems, but also means that your program will have to pay careful attention to threading-specific dangers such as race conditions, deadlocks, livelocks, etc.

For more information on multi-threading, go to your library and borrow any introductory book on operating systems (such as the dinosaur book).

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!