send periodic pings

This commit is contained in:
Zlatin Balevsky
2019-11-11 17:54:33 +00:00
parent bfe0ab7867
commit 3db167bade
3 changed files with 17 additions and 1 deletions

View File

@@ -110,4 +110,8 @@ class ChatClient implements Closeable {
connectThread?.interrupt() connectThread?.interrupt()
connection?.close() connection?.close()
} }
void ping() {
connection?.sendPing()
}
} }

View File

@@ -56,7 +56,10 @@ class ChatManager {
} }
private void connect() { private void connect() {
clients.each { k, v -> v.connectIfNeeded() } clients.each { k, v ->
v.connectIfNeeded()
v.ping()
}
} }
void shutdown() { void shutdown() {

View File

@@ -39,12 +39,21 @@ class ChatServer {
this.settings = settings this.settings = settings
this.trustService = trustService this.trustService = trustService
this.me = me this.me = me
Timer timer = new Timer("chat-server-pinger", true)
timer.schedule({sendPings()} as TimerTask, 1000, 1000)
} }
public void start() { public void start() {
running.set(true) running.set(true)
} }
private void sendPings() {
connections.each { k,v ->
v.sendPing()
}
}
public void handle(Endpoint endpoint) { public void handle(Endpoint endpoint) {
InputStream is = endpoint.getInputStream() InputStream is = endpoint.getInputStream()
OutputStream os = endpoint.getOutputStream() OutputStream os = endpoint.getOutputStream()