|  | @ -1,12 +1,11 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.endpoint.third.platForm;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.third.PcManageWebSocketService;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RestController;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.websocket.*;
 | 
	
		
			
				|  |  | import javax.websocket.server.ServerEndpoint;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.Collection;
 | 
	
		
			
				|  |  | import java.util.Collections;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by Bing on 2021/6/17.
 | 
	
	
		
			
				|  | @ -18,14 +17,14 @@ import java.util.Collections;
 | 
	
		
			
				|  |  | @ServerEndpoint("/cloudCare/noLogin/pcManage/websocket")
 | 
	
		
			
				|  |  | public class PcManageWebSocketServer {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private static Collection<PcManageWebSocketServer> servers = Collections.synchronizedCollection(new ArrayList<PcManageWebSocketServer>());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //与某个客户端的连接会话,需要通过它来给客户端发送数据
 | 
	
		
			
				|  |  |     private Session session;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @OnOpen
 | 
	
		
			
				|  |  |     public void onOpen(Session session){
 | 
	
		
			
				|  |  |         this.session = session;
 | 
	
		
			
				|  |  |         add(this);
 | 
	
		
			
				|  |  |         PcManageWebSocketService.add(this);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void sendMessage(String message) throws IOException {
 | 
	
	
		
			
				|  | @ -34,7 +33,7 @@ public class PcManageWebSocketServer {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @OnClose
 | 
	
		
			
				|  |  |     public void onClose(){
 | 
	
		
			
				|  |  |         remove(this);
 | 
	
		
			
				|  |  |         PcManageWebSocketService.remove(this);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @OnMessage
 | 
	
	
		
			
				|  | @ -48,26 +47,5 @@ public class PcManageWebSocketServer {
 | 
	
		
			
				|  |  |         error.printStackTrace();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static void broadCast(String msg){
 | 
	
		
			
				|  |  |         for (PcManageWebSocketServer bitCoinServer : servers) {
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 bitCoinServer.sendMessage(msg);
 | 
	
		
			
				|  |  |             } catch (IOException e) {
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static int getTotal(){
 | 
	
		
			
				|  |  |         return servers.size();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public static void add(PcManageWebSocketServer server){
 | 
	
		
			
				|  |  |         System.out.println("有新连接加入! 当前总连接数是:"+ servers.size());
 | 
	
		
			
				|  |  |         servers.add(server);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public static void remove(PcManageWebSocketServer server){
 | 
	
		
			
				|  |  |         System.out.println("有连接退出! 当前总连接数是:"+ servers.size());
 | 
	
		
			
				|  |  |         servers.remove(server);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |