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()
connection?.close()
}
void ping() {
connection?.sendPing()
}
}

View File

@@ -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() {

View File

@@ -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()