Skip to content

Commit 2082066

Browse files
committed
other tweaks to server class
1 parent 8d68289 commit 2082066

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
*/
2525

2626
package processing.net;
27+
2728
import processing.core.*;
2829

2930
import java.io.*;
3031
import java.lang.reflect.*;
3132
import java.net.*;
3233

34+
3335
/**
3436
* ( begin auto-generated from Server.xml )
3537
*
@@ -128,6 +130,21 @@ protected void removeIndex(int index) {
128130
}
129131

130132

133+
protected void disconnectAll() {
134+
synchronized (clients) {
135+
for (int i = 0; i < clientCount; i++) {
136+
try {
137+
clients[i].stop();
138+
} catch (Exception e) {
139+
// ignore
140+
}
141+
clients[i] = null;
142+
}
143+
clientCount = 0;
144+
}
145+
}
146+
147+
131148
protected void addClient(Client client) {
132149
if (clientCount == clients.length) {
133150
clients = (Client[]) PApplet.expand(clients);
@@ -215,9 +232,7 @@ public void dispose() {
215232
thread = null;
216233

217234
if (clients != null) {
218-
while(clientCount>0){
219-
disconnect(clients[0]);
220-
}
235+
disconnectAll();
221236
clientCount = 0;
222237
clients = null;
223238
}
@@ -310,15 +325,4 @@ public void write(String data) {
310325
}
311326
}
312327
}
313-
314-
315-
/**
316-
* General error reporting, all corralled here just in case
317-
* I think of something slightly more intelligent to do.
318-
*/
319-
// public void errorMessage(String where, Exception e) {
320-
// parent.die("Error inside Server." + where + "()", e);
321-
// //System.err.println("Error inside Server." + where + "()");
322-
// //e.printStackTrace(System.err);
323-
// }
324328
}

0 commit comments

Comments
 (0)