简体   繁体   English

Java KryoNet BufferUnderflow

[英]Java KryoNet BufferUnderflow

I am having a very odd issue with the latest version of KryoNet. 最新版本的KryoNet出现了一个非常奇怪的问题。 I'm sending a very simple packet from my client and my server, and getting the buffer underflow exception. 我正在从客户端和服务器发送一个非常简单的数据包,并出现缓冲区下溢异常。 I have 4 other registered packets, all of which work flawlessly. 我还有4个其他已注册的数据包,所有这些数据包都可以正常工作。 The packet that is getting the buffer underflow issue has two string variables, and has been tested with both TCP and UPD. 出现缓冲区下溢问题的数据包具有两个字符串变量,并已通过TCP和UPD进行了测试。 The exception occurs when the packet is sent fairly quickly , atlest twice in under a second. 当数据包发送得很快时 ,至少在一秒钟之内两次,就会发生此异常。 Very odd considering I have other packets that are being updated 60 times a second. 考虑到我还有每秒更新60次的其他数据包,这很奇怪。

This issue is very different from other buffer underflow issue's I've researched. 这个问题与我研究过的其他缓冲区下溢问题非常不同。 This issue isn't caused from sending very large data , as the packet has only two String variables. 此问题不是由发送非常大的数据引起的 ,因为数据包只有两个String变量。 This issue also isn't caused by an applet or some other configuration, as I'm running it as an Application currently using LibGDX. 这个问题也不是由applet或其他配置引起的 ,因为我正在将其作为当前使用LibGDX的应用程序来运行。

Do you guys have any ideas on what could be causing this issue? 你们对造成此问题的原因有任何想法吗?

Thank you and I hope you've had a happy holiday, - Jake 谢谢,希望您度过了一个快乐的假期-杰克

SOURCE: https://github.com/SirTrashyton/SquareContest (The class I'm having issues with is Packet05Chat) 消息来源: https : //github.com/SirTrashyton/SquareContest (我遇到问题的班级是Packet05Chat)

After a few hours of testing I found a solution. 经过几个小时的测试,我找到了解决方案。 As it turns out, KryoNet couldn't distinguish between object types. 事实证明,KryoNet无法区分对象类型。 When I sent a String to the server containing something that would be like another object, IE an Integer, a Character, etc, KryoNet would parse the String very oddly and produce an error. 当我将字符串发送到服务器时,该字符串包含类似于另一个对象的内容,例如IE,整数,字符等,KryoNet会非常奇怪地解析字符串并产生错误。

This was easily fixed by adding a suffix to the message, something random like "OK". 可以通过在消息中添加后缀来轻松解决此问题,例如“ OK”之类的随机后缀。 Then when it was sent back by the server I'd replace 'OK' with nothing. 然后,当服务器将其发送回时,我将用任何内容替换“ OK”。

Hope this helps anyone else who is getting this error. 希望这对遇到此错误的其他人有所帮助。

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

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