Home > Back-end >  How the WebSocket forward send Json data
How the WebSocket forward send Json data

Time:09-16

Such as topic, how to use the websocket forward send Json data, implements the strings

CodePudding user response:

Don't know what you want to ask for specific implementation code, or to specific code, please baidu search a handful, copy and paste can be used, I tell you something about thinking
1. The service side is introduced into the websocket dependent, and then build good websocket service
2. The client (B/C) instantiated websocket and connect server
3. Then the server can get the client's connection, arbitrary any string messages sent to the client, the client also can send any string to the service side of the news

CodePudding user response:

Json data is not a format string, you put the Json data toString then

CodePudding user response:

reference 1/f, swing wang reply:
don't know what you want to ask for specific implementation code, or to specific code, please baidu search a handful, copy and paste can be used, I tell you something about thinking
1. The service side is introduced into the websocket dependent, and then build good websocket service
2. The client (B/C) instantiated websocket and connect server
3. Then the server can get the client's connection, arbitrary any string messages sent to the client, the client also can send any string to the service side of the news

Storage of the client only sendText and sendObject function in the Session, the two can send Json, after sending the client can't get a message that
 
For (Map. Entry SessionEntry: clients. EntrySet ()) {
Map Info=new HashMap<> (a);
The info. The put (" id ", clientId);
The info. The put (" MSG ", message);
SessionEntry. GetValue (). GetAsyncRemote () sendText (JSON. ToJSON (info));
}

I tried to send Json, but the client not receive
And into a string of words, the client side also need to call JSON. Parse to turn again
 
For (Map. Entry SessionEntry: clients. EntrySet ()) {
Map Info=new HashMap<> (a);
The info. The put (" id ", clientId);
The info. The put (" MSG ", message);
SessionEntry. GetValue (). GetAsyncRemote () sendText (JSON. ToJSONString (info));
}

CodePudding user response:

https://bbs.csdn.net/topics/397511806 can refer to my previous answer
  • Related