| | |
| | | |
| | | // 客户端连接会话,通过它给客户端发送数据 |
| | | private Session session; |
| | | |
| | | // 客户端上线时刻 |
| | | //private String onLineDt ; |
| | | // 客户端id |
| | | private String id = ""; |
| | | |
| | |
| | | @OnOpen |
| | | public void onOpen(Session session, @PathParam("id") String id) { |
| | | this.session = session; |
| | | //this.onLineDt = DateTime.yyyy_MM_dd_HH_mm_ss() ; |
| | | this.id = id; |
| | | if(this.id == null || this.id.length() == 0){ |
| | | this.id = "" + System.nanoTime() ; |
| | | } |
| | | this.sendMessage(WebSocketHeartBeat.getHeartBeatMessage()); |
| | | |
| | | if (webSocketMap.containsKey(id)) { |
| | |
| | | /** |
| | | * 服务器主动群推送消息 |
| | | */ |
| | | public static void sendAllMessage(String message) throws IOException { |
| | | public static void sendMessage2AllClient(String message) throws IOException { |
| | | ConcurrentHashMap.KeySetView<String, WebSocketServer> ids = webSocketMap.keySet(); |
| | | for (String id : ids) { |
| | | WebSocketServer webSocketServer = webSocketMap.get(id); |
| | |
| | | /** |
| | | * 服务器指定客户端推送消息 |
| | | */ |
| | | public static void sendOneMessage(String message, String id) throws IOException { |
| | | public static void sendMessage2OneClient(String message, String id) throws IOException { |
| | | if (message != null && message.length() != 0 && webSocketMap.containsKey(id)) { |
| | | webSocketMap.get(id).sendMessage(message); |
| | | } else { |