简体   繁体   English

从二进制文件中保存的包中使用Lidgren创建NetIncomingMessage

[英]Creating a NetIncomingMessage with Lidgren from saved package in a binary file

I am using Lidgren networking library to create a real time multiplayer game. 我正在使用Lidgren网络库来创建实时多人游戏。

What I am trying to do is, save all incoming packages (including all bytes) to a peer in a binary file. 我正在尝试做的是,将所有传入的包(包括所有字节)保存到二进制文件中的同位体。 Later when I need to debug some weird behavior of networking, I can load this file and have it load all (or rebuild) the packages that it saved, sequentially. 稍后,当我需要调试一些奇怪的网络行为时,我可以加载该文件,并使其依次加载(或重建)它保存的所有软件包。 This way, I can find how the weird behavior occurred exactly. 这样,我可以找到奇怪的行为是如何发生的。

My question is, how do I recreate this package when I load it from the file? 我的问题是,从文件加载该程序包后如何重新创建它?

It is a NetIncomingMessage that I need to recreate, I assume, and so far I thought of either creating it anew, or sending an NetOutgoingMessage to self, so it hopefully has the same effect I want to achieve, if the first approach fails. 我认为,这是我需要重新创建的NetIncomingMessage,到目前为止,我考虑过重新创建它,或者向自己发送NetOutgoingMessage,因此,如果第一种方法失败了,希望它具有与我想要实现的效果相同的效果。

The way I solved this is by creating an interface (wrapper object) of the NetIncomingMessage which contains a data byte array among other data members, and than have a thread to fill a list of these objects based on the saved incoming time, which is requested and removed (dequeued) from another thread. 我解决此问题的方法是,通过创建NetIncomingMessage的接口(包装对象),该接口在其他数据成员中包含一个数据字节数组,然后有一个线程根据所保存的传入时间填充这些对象的列表,这是请求的并从另一个线程中删除(出队)。 See https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem 参见https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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