消息未以正确的格式到达服务器 - Socket.io
我正在用react-native为android本机重写一个应用程序,我需要重写客户端套接字,该套接字向服务器发送一条消息,通知它已连接呼叫室。
连接顺利,消息发送到服务器,但是消息到达的格式不适合读取,我无法以与在 React 中相同的方式在 java 中执行此操作。
如何将这段代码转换为java?
sendFamiliarJoined = (patientId: any, familiarId: any) => {
if (this.socket) {
this.socket.emit("message", {
id: 'familiarEnteredInRoom',
patientId,
familiarId,
});
}
}
目前在java中我正在像下面的代码一样执行此操作,但消息仍然没有以所需的格式到达
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("id","familiarEnteredInRoom");
jsonObject.addProperty("patientId", patientRepo.getPatientId());
jsonObject.addProperty("familiarId", userRepo.getUSerId());
mSocket.emit("message", "id : familiarLeftRoom", jsonObject);
所需的格式将类似于:
I'm rewriting an app in react-native for android native and I need to rewrite the client socket that sends a message to the server notifying that it has connected the call room.
The connection goes well and the message is sent to the server, however the format that the message arrives is inappropriate for it to be read and I am not able to do it in java in the same way as it is done in react.
How to convert this code to java?
sendFamiliarJoined = (patientId: any, familiarId: any) => {
if (this.socket) {
this.socket.emit("message", {
id: 'familiarEnteredInRoom',
patientId,
familiarId,
});
}
}
Currently in java I'm doing it like the code below but the message still doesn't arrive in the desired format
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("id","familiarEnteredInRoom");
jsonObject.addProperty("patientId", patientRepo.getPatientId());
jsonObject.addProperty("familiarId", userRepo.getUSerId());
mSocket.emit("message", "id : familiarLeftRoom", jsonObject);
The desired format would be something like:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论