Home > Mobile >  Use HBuilderX development of HTML 5 + APP, met questions about webSocket.
Use HBuilderX development of HTML 5 + APP, met questions about webSocket.

Time:09-20

In the first place in the PC simulator is no problem with my cell phone,
Then install the mobile phone use for the first time, the new WebSocket (ws://"url"); Reward 302 state, because the background is shiro framework, the socket directly to the service I cancel landing stopped, but will still preserved in login authentication session object, which can access to the webSocket service class,
 
@ Override
Protected Boolean onLoginSuccess (AuthenticationToken token, the Subject a Subject, ServletRequest request, ServletResponse response) throws the Exception {
Pager Pager=new Pager ();
String username=(String) token. GetPrincipal ();
//get the user
User User=userService. GetUserByUsername (username);
//add user information to the session
The Session Session=subject. GetSession ();
The session. The setAttribute (" user ", the user);
System. The out. Println (session. GetId ());
.


Then problem again, after get the session in the WebSocket service class without the user object, and view the sessionId is inconsistent with the landing
 
@ OnOpen
Public void onOpen (Session Session, EndpointConfig config) {
The httpSession=(httpSession) config. GetUserProperties () get (httpSession. Class. GetName ());
//TODO: PDA access Attributes when no user object in
User User=(User) the httpSession. GetAttribute (" User ");
This. The session=session;
This. UserId=user. GetId ();
System. The out. Println (" have user connection: "+ userId);
WebSocketMap. Put (user. GetId (), this);
.

CodePudding user response:

Dcloud market have a good websocket plugin, trial, stability, good real-time performance, address here: https://ext.dcloud.net.cn/plugin? Id=1334
  • Related