62,614
社区成员
发帖
与我相关
我的任务
分享
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
DataOutputStream dos = new DataOutputStream(baos);
try {
dos.writeInt(ProtocolConst.ConnectMessage);
dos.writeInt(version);
dos.writeBytes(name);
dos.close();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
rcvByte = new byte[2048];
sPacket = new DatagramPacket(rcvByte, rcvByte.length);
ByteArrayInputStream bais = new ByteArrayInputStream(rcvByte, 0, sPacket.getLength());
DataInputStream dis = new DataInputStream(bais);
Log.d(TAG, "type: " + dis.readInt());
Log.d(TAG, "version: " + dis.readInt());
byte[] buf = new byte[1024];
dis.read(buf, 0, 1024);
Log.d(TAG, "name: " + buf.toString());
DataOutputStream dos = new DataOutputStream(baos);
try {
dos.writeInt(ProtocolConst.ConnectMessage);
dos.writeInt(version);
dos.writeBytes(name);
dos.close();
baos.close();
dos.flus();