Server problem, need ideas...
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.
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).
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).
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.
Don't worry about the time it will take. For you, it will seem instantaneous.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement