Sign in to follow this  

Server problem, need ideas...

This topic is 4518 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

Hello, I am making a tcp/ip server for multiple clients. I have an array: CLIENTINFO clients [10000]. CLIENTINFO has some members about each client, one of the members is also the SOCKET that identifies the client. I am using WSAAsyncSelect for the main "listening" socket and for each client. When my WindowProc recieves a message indicating an network event had occured the wParam equals to the SOCKET of the client which made the event. The problem is, I want to know, clients [whatindex?].sock is equal to the wParam. The only way I have found to solve this matter is to do a loop of all the current connected clients and find the matching client but if i do so for each network event the speed would catastrofic!, please suggest ideas to solve this matter.

Share this post


Link to post
Share on other sites
Wow, 10000 is a lot of sockets.

Don't use a vector, use a tree, try std::map.
If you're using TCP, look-up the client based on destination port and verify the IP address's match.
If you're using UDP, look-up the client based on the source IP address and source port (everyone will send to the same destination port in this case, and you only need 1 server socket open not 1 per client, but you have to use datagrams instead of a stream).

Share this post


Link to post
Share on other sites
Urikiller, it doesn't take long at all to loop through 10000 indexs in an array. While there's a BETTER WAY, IF YOU'RE A BEGINNER PROGRAMMER, IT'S CERTAINLY ok TO GO ABOUT IT THIS WAY TO FIND THE INDEX FOR THAT SOCKET. (sorry caps)

Don't worry about the time it will take. For you, it will seem instantaneous.

Share this post


Link to post
Share on other sites

This topic is 4518 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this