发送端:
String line = "hello socket";
DatagramPacket dp = new DatagramPacket(line.getBytes(),
line.length(), InetAddress.getByName("192.168.1.68"),
10086);
ds.send(dp);
接收端:
byte[] b = new byte[1024];
DatagramPacket dp = new DatagramPacket(b, 100);
ds.receive(dp);
问题:
接收端dp.getLength()怎么解析成发送端发过来字符串的长度("hello socket"的长度),而不是100 或1024? |
|