2
\$\begingroup\$

I'm setting up a game with Lidgren, and I was wondering if there was a way to read a message from a certain client instead of just from the server as a whole, such as-

//Why doesn't this exist?
NetIncomingMessage message = server.Connections[0].ReadMessage();

This way I would be able to split up reading data from each client into it's own thread and have a separate thread for sending data to each client. Currently there is only one loop in my server, which reads packets and I fear is favoring one client more than others, as some movements made by players take a while to be received by other players. I believe reading messages separately from each client would solve this issue. With simple TcpClients, you can read from each client's stream instead of the server as a whole, and I like this functionality but also rely on the simplicity of sending packets through Lidgren and was wondering if there was a similar functionality with Lidgren.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Each message has the sender's remote unique identifier as a field. When handling incoming messages just compare the SenderConnection.RemoteUniqueIdentifier to each client's RemoteUniqueIdentifier (you get this on the connection being established).

// read incoming messages
while ((var message = server.ReadMessage()) != null)
{
    // for each existing connection/player
    foreach (var player in Players)
    {
        // if this message is from this player
        if (message.SenderConnection.RemoteUniqueIdentifier == player.RemoteUniqueIdentifier)
        {
            // Handle message
        }
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .