- May 5, 2012
- 284
- 0
- 0
I have a simple C# server app, it handles connections from multiple clients. One thing I need to be able to do is select one client, and communicate with it. To accomplish this I have created a dictionary:
The server is asynchronous, and ever time the callback that accepts a new client is called it adds the socket and a unique ID to the dictionary. Once I have the specific socket I can read and write data from and to the client. The console app takes my input "client:x" and passes x to a method that uses LINQ to select the key(socket) from the database where the value equals x. In my case, the value is always unique, so that's not a problem. But as the dictionary grows, I'm checking every entry in it and just making a brute force check constantly. It also requires framework version 3.5. So I'm wondering what is the proper way to do this? My solution works, but I wouldn't call it ideal.
Code:
Dictionary<Socket, int> clients = new Dictionary<Socket, int>();
Last edited: