Skip to content

Commit fca5908

Browse files
committed
Fixed missing disconnect for some clients
1 parent 0b50a98 commit fca5908

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

java/libraries/net/src/processing/net/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public Client(PApplet parent, Socket socket) throws IOException {
151151
* @usage application
152152
*/
153153
public void stop() {
154-
if (disconnectEventMethod != null) {
154+
if (disconnectEventMethod != null && thread != null){
155155
try {
156156
disconnectEventMethod.invoke(parent, new Object[] { this });
157157
} catch (Exception e) {

java/libraries/net/src/processing/net/Server.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,7 @@ public Server(PApplet parent, int port) {
109109
* @param client the client to disconnect
110110
*/
111111
public void disconnect(Client client) {
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;
117-
client.dispose();
112+
client.stop();
118113
int index = clientIndex(client);
119114
if (index != -1) {
120115
removeIndex(index);
@@ -220,8 +215,8 @@ public void dispose() {
220215
thread = null;
221216

222217
if (clients != null) {
223-
for (int i = 0; i < clientCount; i++) {
224-
disconnect(clients[i]);
218+
while(clientCount>0){
219+
disconnect(clients[0]);
225220
}
226221
clientCount = 0;
227222
clients = null;

0 commit comments

Comments
 (0)