Jump to content
  • Advertisement
Sign in to follow this  
UriKiller

Server problem, need ideas...

This topic is 4732 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
Advertisement
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
I'm with Shannon; use a map (or dictionary, depending on the teacher). std::map<fromtype,totype> ought to work in C++, or just brew yourself up a binary search tree if you're in C.

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!