Home Forums Support Storing client connection information on server? Reply To: Storing client connection information on server?

#951
Anonymous
Inactive

Heya Tomas,

Good to hear you are making progress. The best answer to your question is that you can decide what the best communication configuration is and then use Networkcomms.Net to implement it. You are not really restricted to one configuration over another. A very brief example of what you might be able to use is:

List<IPEndPoint> connectedClients = new List<IPEndPoint>();
NetworkComms.AppendGlobalIncomingPacketHandler<string>("InitialClientConnect", (header, connection, message) =>
    {
        //If a client sends a InitialClientConnect packet we add them to the connectedClients list
        connectedClients.Add(connection.ConnectionInfo.RemoteEndPoint);
    });

and

//At some future point we can send something to all connected clients
string messageToSend = "helloWorld";
foreach (IPEndPoint endPoint in connectedClients.ToList())
{
    try
    {

        TCPConnection.GetConnection(new ConnectionInfo(endPoint)).SendObject("TestMessage", messageToSend);
    }
    catch (CommsException ex)
    {
        //An exception occured. Inspect the exception 'ex' to determine what went wrong
        //It might be the client is no longer available
    }
}

Regards,
Marc