[英]PingIDs (Data) is different on different sides
I am working on a server software for Minecraft: Pocket Edition. 我正在为Minecraft:Pocket Edition开发服务器软件。 Right now I am working on the MOTD for the server, and it works Just fine.
现在,我正在为服务器开发MOTD,并且工作正常。 When sending a response to a ping packet (0x01) with a 0x1c.
发送对带有0x1c的ping数据包(0x01)的响应时。 It shows up in the world list with the name just fine.
它以很好的名称显示在世界列表中。 But, for some reason, If I send the same data from another program, the Ping ID and ServerID will show different in the consoles.
但是,由于某种原因,如果我从另一个程序发送相同的数据,则Ping ID和ServerID在控制台中将显示不同。 Why is this?
为什么是这样?
Ping response code: Ping响应代码:
public PingResponse(DatagramPacket Packet, long ServerID) throws IOException {
// Data from Ping
ByteBuffer ReceivedPing = ByteBuffer.wrap(Packet.getData());
// Set variables
this.ServerID = ServerID;
this.ServerName = ServerPropertiesHandler.getMOTD();
this.PingID = ReceivedPing.getLong();
// Server Name
String Identifier = "MCCPP;MINECON;" + ServerPropertiesHandler.getMOTD();
ByteBuffer PingResponseBuffer = ByteBuffer.allocate(35 + (short) Identifier.length());
// Put Packet ID
PingResponseBuffer.put(PacketIDList.ID_UNCONNECTED_PING_OPEN_CONNECTIONS);
// Ping ID
PingResponseBuffer.putLong(this.PingID);
System.out.println("Ping ID: " + this.PingID);
// Server ID
PingResponseBuffer.putLong(this.ServerID);
System.out.println("Server ID: " + this.ServerID);
// Sugar Spice and everything nice
PingResponseBuffer.put(PacketIDList.MAGIC);
// Server Name
PingResponseBuffer.putShort((short) Identifier.length());
PingResponseBuffer.put(Identifier.getBytes());
// Send
PacketHandler.Socket.send(new DatagramPacket(PingResponseBuffer.array(), PingResponseBuffer.array().length), Packet.getAddress(), Packet.getPort());
}
Client Example: 客户示例:
public static void main(String[] args) {
try {
// SEND
final long PacketID = new Random().nextLong();
DatagramSocket ClientSocket = new DatagramSocket();
ByteBuffer PingBuffer = ByteBuffer.allocate(25);
PingBuffer.put(PacketIDList.ID_CONNECTED_PING_OPEN_CONNECTIONS);
PingBuffer.putLong(PacketID);
PingBuffer.put(PacketIDList.MAGIC);
ClientSocket.send(new DatagramPacket(PingBuffer.array(), PingBuffer.array().length, InetAddress.getByName("localhost"), 19132));
// RECEIVE
byte[] buffer = new byte[1535];
DatagramPacket PongPacket = new DatagramPacket(buffer, buffer.length);
ClientSocket.receive(PongPacket);
byte[] PongPacketData = PongPacket.getData();
ByteBuffer PongBuffer = ByteBuffer.wrap(PongPacketData);
if(PongPacketData[0] == (byte) 0x1c) {
System.out.println("PingID From Server: " + PongBuffer.getLong());
System.out.println("ServerID From Server: " + PongBuffer.getLong());
System.out.println("MAGIC From Server: " + PongBuffer.get());
System.out.println("MOTD From Server: " + PongBuffer.get());
}
else {
System.out.println("UNKNOWN PACKET");
}
ClientSocket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
3 months and no reply. 3个月,无回复。 pingID and serverID are identifiers of time used on respective systems to determine the time since start.
pingID和serverID是在各个系统上用来确定自启动以来的时间的时间标识符。 These provide a double functionality.
这些提供双重功能。 Firstly, they allow a server to determine any latency in the communications.
首先,它们允许服务器确定通信中的任何延迟。 Secondly, they help provide a packet order to commands.
其次,它们有助于为命令提供数据包顺序。 Rebooting a server would generate a new serverID starting from 0, while rejoining a server would provide a new pingID starting at 0.
重新引导服务器将生成从0开始的新serverID,而重新加入服务器将提供从0开始的新pingID。
I would be quite interested to see the progress you've made, as I've begun working on my own. 当我开始自己工作时,我很想知道您所取得的进步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.