/** 会话抛出异常 */ @Override public void handleTransportError(WebSocketSession session, Throwable arg1) throws Exception { // TODO Auto-generated method stub if (session.isOpen()) { session.close(); } WebSocketCache.removeMemberSession(session); }
/** 处理会话 */ @Override public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception { // TODO Auto-generated method stub Map<String, String> select = JsonUtil.jsonToMap(message.getPayload().toString()); String result = webSocketService.getNewMessage(select); session.sendMessage(new TextMessage(result.toString())); WebSocketCache.putMemberSession(select.get("userId"), session); }
/** 连接成功 */ @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { // TODO Auto-generated method stub System.out.println(session); Map<String, String> select = new HashMap<String, String>(); String userId = (String) session.getAttributes().get("userId"); String userPwd = (String) session.getAttributes().get("userPwd"); select.put("userId", userId); select.put("userPwd", userPwd); String result = webSocketService.getNewMessage(select); session.sendMessage(new TextMessage(result.toString())); WebSocketCache.putMemberSession(select.get("userId"), session); }
/** 会话关闭 */ @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus arg1) throws Exception { WebSocketCache.removeMemberSession(session); }