diff options
author | Vitaly Takmazov | 2017-01-12 23:07:18 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-01-12 23:07:18 +0300 |
commit | a911c89be8a8b8e89086536939684b2720b2cfa2 (patch) | |
tree | cd9451b515ee1ea74b579bfd1259d988eeee7411 /juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java | |
parent | fd8832275421bf2c6f17947aefa236bd65ef1650 (diff) |
juick-ws: ping websocket clients
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java')
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java index 32888797..81f636a7 100644 --- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java @@ -10,7 +10,9 @@ import org.apache.http.client.utils.URLEncodedUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.PingMessage; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; @@ -117,6 +119,17 @@ public class WebsocketComponent extends TextWebSocketHandler { } + @Scheduled(fixedRate = 30000) + public void ping() { + clients.forEach(c -> { + try { + c.session.sendMessage(new PingMessage()); + } catch (IOException e) { + logger.error("WebSocket PING exception", e); + } + }); + } + public List<SocketSubscribed> getClients() { return clients; } |