diff --git a/core/src/main/groovy/com/muwire/core/chat/ChatClient.groovy b/core/src/main/groovy/com/muwire/core/chat/ChatClient.groovy index a2e883c3..3e7dd791 100644 --- a/core/src/main/groovy/com/muwire/core/chat/ChatClient.groovy +++ b/core/src/main/groovy/com/muwire/core/chat/ChatClient.groovy @@ -110,4 +110,8 @@ class ChatClient implements Closeable { connectThread?.interrupt() connection?.close() } + + void ping() { + connection?.sendPing() + } } diff --git a/core/src/main/groovy/com/muwire/core/chat/ChatManager.groovy b/core/src/main/groovy/com/muwire/core/chat/ChatManager.groovy index 7f31e4bb..e625b87e 100644 --- a/core/src/main/groovy/com/muwire/core/chat/ChatManager.groovy +++ b/core/src/main/groovy/com/muwire/core/chat/ChatManager.groovy @@ -56,7 +56,10 @@ class ChatManager { } private void connect() { - clients.each { k, v -> v.connectIfNeeded() } + clients.each { k, v -> + v.connectIfNeeded() + v.ping() + } } void shutdown() { diff --git a/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy b/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy index e9cfab65..03aaff7b 100644 --- a/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy +++ b/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy @@ -39,12 +39,21 @@ class ChatServer { this.settings = settings this.trustService = trustService this.me = me + + Timer timer = new Timer("chat-server-pinger", true) + timer.schedule({sendPings()} as TimerTask, 1000, 1000) } public void start() { running.set(true) } + private void sendPings() { + connections.each { k,v -> + v.sendPing() + } + } + public void handle(Endpoint endpoint) { InputStream is = endpoint.getInputStream() OutputStream os = endpoint.getOutputStream()