gpt4 book ai didi

java - 如何从 DatagramPacket 中检索字符串

转载 作者:行者123 更新时间:2023-11-30 11:45:51 25 4
gpt4 key购买 nike

<分区>

下面的代码打印

[B@40545a60,[B@40545a60abc exp 

但我想打印abc,这样我就可以从接收系统中检索到正确的消息。

public class Operation {
InetAddress ip;
DatagramSocket dsock;
DatagramPacket pack1;
byte[] bin,bout;
WifyOperation(InetAddress Systemip)
{
ip=Systemip;
try {
dsock=new DatagramSocket();

} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

void sendbyte()
{
String senddata="abc";
bout=senddata.getBytes();
pack1=new DatagramPacket(bout,bout.length,ip,3322);
try {
dsock.send(pack1);
Log.d(pack1.getData().toString(),"abc exp");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

如何从数据包 pack1 中检索字符串而不是字节?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com