My application has many tcpclients that is uses to update hundreds of servers when instructed. I'm having trouble in the design with a minor but important issue.
My programs takes an outgoing message out of a queue and selects an available client from an array of clients, I'll call this client1. It starts a connection on the tcpclient with a BeginConnect and issues a call back method. The program then moves on to other messages from the queue and the tcpclients that will be sending them.
When the the callback happens for client1, my program gets an AsyncResult from which I can resolve the socket.
Here is my problem. How do I know which socket or TCPClient I have? It's important because I need to know which message to send on this connected client.
I've looked on the socket and didn't find a name property.
How do I identify the socket so I know the correct messaging conversation to have?
Thanks!
After more study and research I realized the callback would pass any System.Object. So the answer is as simple as wrapping the TCPClient in a class that has properties that can identify it's purpose.
In my case a simple class with a Socket, String for the message, string for the IP, and an int for the Port was enough to handle the situate when it made it to the call back. Just remember you have to cast the IAsyncResult.AsyncState back to the type of your wrapper class.