Winsock Server/Client Connections
I have wrote a basic Client / Server application in C++ with the server updating a MySQL database. I have this app working with a single user connected. I am updating it to accept multiple connections. My question is when the server is waiting/listening to a socket for new connectings my server stops processing data from the client already connected. Could someone show me the logic for a server that can listen for new connections and still continue to run through the program? I have looked through the forum FAQ and done lots of Googleing to no result. There are lots of simple client/server examples out there but none show a solution to my problem. Thanks in advance, MarkSponge
Well, I cannot really give you an example. And I use MFC for sockets. But I would suggest using threads for each client that is connected. There are plenty of places on the internet that talk about client/server applications that use threads for multiple connections with clients. Try googling for threads, or visit CodeProject.com. =) Hope that helps.
:==-_ Why don't the voices just leave me alone?! _-==:
I went the single threaded route, and used non-blocking IO.
Here is my class set, along with a main.cpp file to demonstrate how it handles multiple connects/sends/receives "at the same time".
http://ada.podzone.org/taby/sock.zip
To run the server, simply start the executable.
To run a client, hold shift while starting the executable. You can run many clients at once obviously.
Here is my class set, along with a main.cpp file to demonstrate how it handles multiple connects/sends/receives "at the same time".
http://ada.podzone.org/taby/sock.zip
To run the server, simply start the executable.
To run a client, hold shift while starting the executable. You can run many clients at once obviously.
Actually multiple threads performance wise is just good in a multi core system, and even with a multicore system you want to keep the amount of working threads as close to the number of cores as possible.
So for a single core system you'll probably be better off, like taby said, just using non-blocking IO, with the select() model, WSAAsyncSelect() model, WSAEventSelect model, the Overlapped model or the, ever so famous for it's performance, IOCP model.
You can read further details about these models on "Network Programming for Microsoft Windows" or searching the web for server models, these names are bound to come up.
So for a single core system you'll probably be better off, like taby said, just using non-blocking IO, with the select() model, WSAAsyncSelect() model, WSAEventSelect model, the Overlapped model or the, ever so famous for it's performance, IOCP model.
You can read further details about these models on "Network Programming for Microsoft Windows" or searching the web for server models, these names are bound to come up.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement