mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 10:55:38 +01:00
Implements disconnectEvent for the Server code as requested in Issue #2133
This commit is contained in:
@@ -118,6 +118,7 @@ public class Client implements Runnable {
|
||||
* @throws IOException
|
||||
*/
|
||||
public Client(PApplet parent, Socket socket) throws IOException {
|
||||
this.parent = parent;
|
||||
this.socket = socket;
|
||||
|
||||
input = socket.getInputStream();
|
||||
@@ -125,6 +126,16 @@ public class Client implements Runnable {
|
||||
|
||||
thread = new Thread(this);
|
||||
thread.start();
|
||||
|
||||
// reflection to check whether host sketch has a call for
|
||||
// public void disconnectEvent(processing.net.Client)
|
||||
try {
|
||||
disconnectEventMethod =
|
||||
parent.getClass().getMethod("disconnectEvent",
|
||||
new Class[] { Client.class });
|
||||
} catch (Exception e) {
|
||||
// no such method, or an error.. which is fine, just ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -109,7 +109,11 @@ public class Server implements Runnable {
|
||||
* @param client the client to disconnect
|
||||
*/
|
||||
public void disconnect(Client client) {
|
||||
//client.stop();
|
||||
//Calling client.stop() here would cause duplicate
|
||||
//calls to disconnectEvent in the containing sketch,
|
||||
//once for the stop() and once for the terminated connection.
|
||||
//Instead just dispose of the client and let the terminated
|
||||
//connection generate the disconnectEvent message;
|
||||
client.dispose();
|
||||
int index = clientIndex(client);
|
||||
if (index != -1) {
|
||||
|
||||
Reference in New Issue
Block a user