简体   繁体   English

如何用Java格式化UDP数据包?

[英]How to format UDP packet in Java?

I need to send some data to an IP address with UDP. 我需要使用UDP将一些数据发送到IP地址。 I don't know how to format my string. 我不知道如何格式化我的字符串。 Am i need to send multiple data packets? 我需要发送多个数据包吗?

From the developer page I only get this information: 在开发人员页面上,我仅获得以下信息: 在此处输入图片说明

What am I supposed to do? 我应该做些什么? In the right section it's the string that I need to send. 在右侧部分,这是我需要发送的字符串。

Could anyone explain what does mean "Challenge"? 谁能解释什么是“挑战”?

From the developers site: 从开发者站点:

Shortly after a game server has been initialized, it picks two master servers to "join." 初始化游戏服务器后不久,它将选择两个主服务器“加入”。 In order for clients to see a particular game server when they click on the "Internet" tab, the game server must be present in the Steam master servers' records. 为了使客户端在单击“ Internet”选项卡时看到特定的游戏服务器,游戏服务器必须出现在Steam主服务器记录中。 The game server sends each master server "q" (71). 游戏服务器向每个主服务器发送“ q”(71)。 The master servers each respond by sending FF FF FF FF 73 0A followed by a (relatively) unique 4-byte "challenge" number. 每个主服务器通过发送FF FF FF FF 73 0A响应,后跟一个(相对)唯一的4字节“挑战”号。 If you send the master servers an invalid challenge, you will get another challenge as a response. 如果向主服务器发送无效的质询,您将收到另一个质询作为响应。

What does this mean? 这是什么意思?

FF FF FF FF 73 0A FF FF FF FF 73 0A

As I wrote in my comment, you need to send bytes, not really a string. 正如我在评论中所写,您需要发送字节,而不是字符串。 So you'll have to find out if the server works with ascii encoding or something different and then get the bytes for your strings in the correct encoding. 因此,您必须找出服务器是否以ascii编码或其他方式工作,然后以正确的编码获取字符串的字节。

When the docu talks about "sending FF 73 ... " it means sending bytes. 当文档讨论“发送FF 73 ...”时,表示发送字节。 It is a number in base 16 (="Hexadecimal"). 它是一个以16为底的数字(=“ Hexadecimal”)。 A byte "FF" is created for example like this : 像这样创建一个字节“ FF”:

byte b = 0xFF; // Hex for 255

When the docu talks about sending "q(71)" it means sending a byte (0x71) which encodes the letter "q" in ascii. 当文档讨论发送“ q(71)”时,意味着发送一个字节(0x71),该字节以ascii编码字母“ q”。

About the "challenge" read Wikipedia and consult the developer docu a little bit deeper. 关于“挑战”,请阅读Wikipedia,并更深入地咨询开发人员文档。 I am sure they say more on that matter. 我相信他们会在这个问题上说更多。

On using UDP in Java you can consult many examples and the tutorials from oracle . 在Java中使用UDP时,您可以查阅oracle的许多示例和教程

I hope this is helpful to you. 希望对您有帮助。 Good luck. 祝好运。

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

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