正在显示
1 个修改的文件
包含
4 行增加
和
8 行删除
| 1 | package com.sunyo.wlpt.cgonms.provide.websocket; | 1 | package com.sunyo.wlpt.cgonms.provide.websocket; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import cn.hutool.json.JSON; | ||
| 5 | import cn.hutool.json.JSONObject; | 4 | import cn.hutool.json.JSONObject; |
| 6 | import cn.hutool.json.JSONUtil; | 5 | import cn.hutool.json.JSONUtil; |
| 7 | import cn.hutool.log.Log; | 6 | import cn.hutool.log.Log; |
| 8 | import cn.hutool.log.LogFactory; | 7 | import cn.hutool.log.LogFactory; |
| 8 | +import com.alibaba.fastjson.JSON; | ||
| 9 | import com.sunyo.wlpt.cgonms.provide.controller.NmsController; | 9 | import com.sunyo.wlpt.cgonms.provide.controller.NmsController; |
| 10 | import com.sunyo.wlpt.cgonms.provide.response.ResultJson; | 10 | import com.sunyo.wlpt.cgonms.provide.response.ResultJson; |
| 11 | +import com.sunyo.wlpt.cgonms.provide.response.ResultWs; | ||
| 11 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
| 12 | 13 | ||
| 13 | import javax.annotation.Resource; | 14 | import javax.annotation.Resource; |
| @@ -53,13 +54,8 @@ public class WebSocketServer { | @@ -53,13 +54,8 @@ public class WebSocketServer { | ||
| 53 | log.info("有新窗口开始监听:" + sid + ",当前在线人数为" + getOnlineCount()); | 54 | log.info("有新窗口开始监听:" + sid + ",当前在线人数为" + getOnlineCount()); |
| 54 | this.sid = sid; | 55 | this.sid = sid; |
| 55 | try { | 56 | try { |
| 56 | - String openMessage = "{\n" + | ||
| 57 | - " \"sid\":\"" + sid + "\",\n" + | ||
| 58 | - " \"session\":\"" + session + "\",\n" + | ||
| 59 | - " \"message\": \"连接成功\",\n" + | ||
| 60 | - " \"data\":{\"flightdate\":\"2015-02-05\",\"flightNo\":\"CV987\"}\n" + | ||
| 61 | - "}"; | ||
| 62 | - sendMessage(openMessage); | 57 | + String resultStart = JSON.toJSONString(new ResultWs("连接成功,可以开始查询!" )); |
| 58 | + sendMessage(resultStart); | ||
| 63 | } catch (IOException e) { | 59 | } catch (IOException e) { |
| 64 | log.error("websocket IO异常"); | 60 | log.error("websocket IO异常"); |
| 65 | } | 61 | } |
-
请 注册 或 登录 后发表评论