| | |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.concurrent.Semaphore; |
| | | |
| | | @ServerEndpoint(value = "/api/talk/{username}") |
| | | @ServerEndpoint(value = "/api/talk/{webSocketName}") |
| | | @Component |
| | | public class WebSocketServer { |
| | | |
| | |
| | | * 向当前用户的所有会话发送消息 |
| | | */ |
| | | public void sendToWeb(String webSocketName, String message) { |
| | | List<WebSocketServer> sessions = sessionMap.get(webSocketName); |
| | | List<WebSocketServer> sessions = sessionMap.get(webSocketName); |
| | | if (sessions == null) return; |
| | | sessions.forEach(ws -> { |
| | | try { |
| | |
| | | /** |
| | | * 分块发送大消息 |
| | | */ |
| | | private void sendChunkedMessage(String message) { |
| | | private synchronized void sendChunkedMessage(String message) { |
| | | if (!session.isOpen()) return; |
| | | try { |
| | | if (message.length() <= MAX_MESSAGE_SIZE) { |