diff --git a/java/libraries/net/src/processing/net/Client.java b/java/libraries/net/src/processing/net/Client.java index 18867e5dc..a93baa838 100644 --- a/java/libraries/net/src/processing/net/Client.java +++ b/java/libraries/net/src/processing/net/Client.java @@ -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 + } } diff --git a/java/libraries/net/src/processing/net/Server.java b/java/libraries/net/src/processing/net/Server.java index 12b73a71b..cdc81a386 100644 --- a/java/libraries/net/src/processing/net/Server.java +++ b/java/libraries/net/src/processing/net/Server.java @@ -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) {