| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c119388 commit 252a68e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,13 +118,24 @@ public Client(PApplet parent, String host, int port) { | |||
| 118 | 118 | * @throws IOException | |
| 119 | 119 | */ | |
| 120 | 120 | public Client(PApplet parent, Socket socket) throws IOException { | |
| 121 | + this.parent = parent; | ||
| 121 | 122 | this.socket = socket; | |
| 122 | 123 | ||
| 123 | 124 | input = socket.getInputStream(); | |
| 124 | 125 | output = socket.getOutputStream(); | |
| 125 | 126 | ||
| 126 | 127 | thread = new Thread(this); | |
| 127 | 128 | thread.start(); | |
| 129 | + | ||
| 130 | + // reflection to check whether host sketch has a call for | ||
| 131 | + // public void disconnectEvent(processing.net.Client) | ||
| 132 | + try { | ||
| 133 | + disconnectEventMethod = | ||
| 134 | + parent.getClass().getMethod("disconnectEvent", | ||
| 135 | + new Class[] { Client.class }); | ||
| 136 | + } catch (Exception e) { | ||
| 137 | + // no such method, or an error.. which is fine, just ignore | ||
| 138 | + } | ||
| 128 | 139 | } | |
| 129 | 140 | ||
| 130 | 141 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,7 +109,11 @@ public Server(PApplet parent, int port) { | |||
| 109 | 109 | * @param client the client to disconnect | |
| 110 | 110 | */ | |
| 111 | 111 | public void disconnect(Client client) { | |
| 112 | - //client.stop(); | ||
| 112 | + //Calling client.stop() here would cause duplicate | ||
| 113 | + //calls to disconnectEvent in the containing sketch, | ||
| 114 | + //once for the stop() and once for the terminated connection. | ||
| 115 | + //Instead just dispose of the client and let the terminated | ||
| 116 | + //connection generate the disconnectEvent message; | ||
| 113 | 117 | client.dispose(); | |
| 114 | 118 | int index = clientIndex(client); | |
| 115 | 119 | if (index != -1) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments