send periodic pings
This commit is contained in:
@@ -110,4 +110,8 @@ class ChatClient implements Closeable {
|
|||||||
connectThread?.interrupt()
|
connectThread?.interrupt()
|
||||||
connection?.close()
|
connection?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ping() {
|
||||||
|
connection?.sendPing()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user