【发布时间】:2011-09-08 15:17:52
【问题描述】:
伙计们!我正在编写一个简单的程序来向游戏服务器发送消息(反恐精英),该消息用于查询服务器信息,它具有固定格式:
0xff, 0xff, 0xff, 0xff, 0x54, 0x53, 0x6f, 0x75,
0x72, 0x63, 0x65, 0x20, 0x45, 0x6e, 0x67, 0x69,
0x6e, 0x65, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79,
0x00
我的java程序:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class Test {
private static DatagramSocket ds;
/**
* @param args
*/
public static void main(String[] args) {
try {
ds = new DatagramSocket(27022);
byte[] data;
// TSource Engine Query
char peer0_0[] = {
0xff, 0xff, 0xff, 0xff,
0x54, 0x53, 0x6f, 0x75,
0x72, 0x63, 0x65, 0x20,
0x45, 0x6e, 0x67, 0x69,
0x6e, 0x65, 0x20, 0x51,
0x75, 0x65, 0x72, 0x79, 0x00
};
data = new String(peer0_0).getBytes();
System.out.println("send: " + new String(data));
DatagramPacket dp = new DatagramPacket(data, 0, data.length, InetAddress.getByName("219.133.59.20"), 27021);
ds.send(dp);
byte[] rec = new byte[1024];
DatagramPacket dp2 = new DatagramPacket(rec, 1024);
ds.receive(dp2);
System.out.println("receive: " + new String(rec));
ds.close();
} catch (IOException e) {
e.printStackTrace();
if(ds != null) ds.close();
}
}
}
但是当我运行它时,我使用wireshark来捕获数据包,我得到了这个:
前四个字节是 0x3f 而不是 0xff,那有什么问题呢?我在windows 7中文版上运行java 6。
【问题讨论】:
标签: java networking udp