简体   繁体   中英

Read message from a certain client in Lidgren

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.

You can read messages on one thread, then stuff them into a concurrent safe collection in the, for example, connection.Tag message. Each individual thread would then dequeue messages for that connection. However; it sounds like a really bad solution to a problem that I assume is a bug in the existing code... there's no reason reading messages on a single thread would favor any client over another; messages are enqueued and dequeued in the exact order they arrive. Doing one thread per client will create a whole bunch of synchronization issues you must solve when acting on the content of your received messages; I would advice against it unless you have a very compelling reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM