Enet客户端在时间问题后自动断开连接
所以我开始使用 Enet,我真的很喜欢它,但我正在做一些测试,从客户端向服务器发送信息(每秒 60 次),服务器成功接收这些数据包(每秒 60 次),一切进展顺利直到服务器随机停止接收数据包。
经过进一步测试,我发现客户端正在发送断开连接数据包,我不确定为什么。如果有人对 Enet 有任何了解可以帮助我,我将不胜感激。我目前唯一能想到的是客户端超时了。
好的,凌晨 4:30 是这个问题背后的解释。在我最后一个清醒的脑细胞中,我注意到一行代码的参数为 5000 毫秒,因为我每分钟调用我的代码 60 次,它在大约 30 秒左右超时,这是因为我有一行代码在错误的位置...吸取教训,午夜后不要在 stackoverflow 上发布问题...
- 我不知道如何删除帖子,这有点无用
So I have started using Enet and I really like it but I was doing some testing sending information from a client to a server ( 60 times per second) and the server was successfully receiving these packets ( 60 times per second) and all was going well until randomly the server stops receiving packets.
After further testing I found out that the client is sending a disconnect packet, I am not sure why. If anyone has any knowledge of Enet that could help me out it would be greatly appreciated. Only thing I can currently think of is that the client is timing out.
Okay so 4:30 AM is the explanation behind this issue. With my last awake braincell I noticed a line of code with the an argument of 5000 ms, because I'm calling my code 60 times every minute and it was timing out at about 30 seconds or so it was because I had a line of code in the wrong spot... Lesson learned, don't post questions on stackoverflow after midnight...
- I'm not sure how to delete posts this was kind of useless
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近也遇到了这个问题,解决方案是两个主机(客户端和服务器)都需要定期调用
enet_host_service
,否则另一端会超时,就像发送了断开连接一样。这是因为一些示例客户端/服务器代码不会在客户端中调用
enet_host_service
。enet_host_service
进行一些内务处理,确保双方知道另一端还活着等等。I ran into this problem recently too, and the solution is that both hosts (client and server) need to call
enet_host_service
regularly, otherwise the other end will time out as if a disconnect was sent.This is because some sample client/server code floating around doesn't bother calling
enet_host_service
in the client.enet_host_service
does a bit of housekeeping, making sure that both sides are aware that the other end is alive and so on.