|
@@ -33,17 +33,18 @@ public class WssSession implements WssSendable , Serializable {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public void sendMessage(WsMessageTypeEnum type, Object object) {
|
|
public void sendMessage(WsMessageTypeEnum type, Object object) {
|
|
|
-
|
|
|
|
|
- //组织成形如 message:{"type":"type", "data":{...}}想
|
|
|
|
|
- JSONObject result = new JSONObject();
|
|
|
|
|
- result.putOpt("type", type.type);
|
|
|
|
|
- result.putOpt("content", JSONUtil.toJsonStr(object));
|
|
|
|
|
-
|
|
|
|
|
- logger.info("[WS-SENDMESSAGE],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
|
|
|
|
|
- try {
|
|
|
|
|
- getSession().getBasicRemote().sendText(WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- logger.info("[WS-SENDMESSAGE],[失败],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
|
|
|
|
|
|
|
+ if (session.isOpen()) {
|
|
|
|
|
+ //组织成形如 message:{"type":"type", "data":{...}}想
|
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
|
|
+ result.putOpt("type", type.type);
|
|
|
|
|
+ result.putOpt("content", JSONUtil.toJsonStr(object));
|
|
|
|
|
+
|
|
|
|
|
+ logger.info("[WS-SENDMESSAGE],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
|
|
|
|
|
+ try {
|
|
|
|
|
+ getSession().getBasicRemote().sendText(WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.info("[WS-SENDMESSAGE],[失败],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|