java UDP通信中十六进制的接收与发送
找了网上通用的UDP程序,当用字符串发送时如"1234567890",我这边接到显示的也有"1234567890",然而,当那边用16进制发时,我收到的是:"4vx3F"...
找了网上通用的UDP程序,当用字符串发送时如"1234567890",我这边接到显示的也有"1234567890",然而,当那边用16进制发时,我收到的是:
"
4
v
x
3F"
每两个字节为一组输出,且当数据中第一位为8或9时输出的均为3F,我想正常接收十六进制啊....急,关键是看不到解析这个数据包的过程,不知它是接的是什么,以何种形式解析为String。高手帮帮我...
我写的程序如下:
public class Test {
public Test(){
try {
byte[] buf = new byte[1024];
DatagramSocket ds = new DatagramSocket(8000);
DatagramPacket dp = new DatagramPacket(buf, buf.length);
while (true) {
Arrays.fill(buf,(byte)0);
ds.receive(dp);
String x = new String(dp.getData(),0,dp.getLength());
System.out.println(x);
}
}
catch (SocketException e1) {
System.out.println("SocketException");}
catch (UnknownHostException e11) {
System.out.println("UnknownHostException");}
catch (IOException e) {
System.out.println("IOException");}
}
public static void main(String[] args){
new Test();
}
} 展开
"
4
v
x
3F"
每两个字节为一组输出,且当数据中第一位为8或9时输出的均为3F,我想正常接收十六进制啊....急,关键是看不到解析这个数据包的过程,不知它是接的是什么,以何种形式解析为String。高手帮帮我...
我写的程序如下:
public class Test {
public Test(){
try {
byte[] buf = new byte[1024];
DatagramSocket ds = new DatagramSocket(8000);
DatagramPacket dp = new DatagramPacket(buf, buf.length);
while (true) {
Arrays.fill(buf,(byte)0);
ds.receive(dp);
String x = new String(dp.getData(),0,dp.getLength());
System.out.println(x);
}
}
catch (SocketException e1) {
System.out.println("SocketException");}
catch (UnknownHostException e11) {
System.out.println("UnknownHostException");}
catch (IOException e) {
System.out.println("IOException");}
}
public static void main(String[] args){
new Test();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询