我正在尝试通过套接字将包裹发送到 Android 应用程序。客户端在 libbinder(c++) 中,服务器是一个必须重建包裹的 android 应用程序。我一直在寻找解决方案有一段时间了,但我不知道如何序列化包裹,然后在服务器端重新构建它。关于如何做到这一点有什么想法吗?
谢谢
我处理数据的代码部分
客户端
Parcel parc = Parcel();
double three = 5.5;
parc.writeDouble(three);
unsigned char b[sizeof(parc)];
std::memcpy(b, &parc, sizeof(parc));
然后我这样发送
send(client, b, sizeof(b), 0);
服务器
private int count
private InputStream in = null;
try {
in = socket.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
try {
count = in.read(bytes);
}catch (IOException e) {
e.printStackTrace();
}
Parcel parcel = Parcel.obtain();
parcel.unmarshall(bytes, 0, bytes.length);
parcel.setDataPosition(0);
double d = parcel.readDouble();
Log.v("----double---", "double" + d);
最佳答案
可以找到一个很好的例子here .
通常,您需要确保您拥有可用于重建(从包裹创建)对象的类。
关于java - 通过 socket 包裹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41067488/