Winsock server with c++??
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
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.
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.
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.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
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.
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).
enum Bool { True, False, FileNotFound };
Thankyou everyone.
That clears it up. I'm going to omit "multithread" from my Google searches from now on.
Thanks again.
Mark
That clears it up. I'm going to omit "multithread" from my Google searches from now on.
Thanks again.
Mark
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement