Fixed missing disconnect for some clients

This commit is contained in:
Kyle Feuz
2014-04-18 15:48:14 -07:00
parent 0b50a98219
commit fca59082a8
2 changed files with 4 additions and 9 deletions

View File

@@ -151,7 +151,7 @@ public class Client implements Runnable {
* @usage application
*/
public void stop() {
if (disconnectEventMethod != null) {
if (disconnectEventMethod != null && thread != null){
try {
disconnectEventMethod.invoke(parent, new Object[] { this });
} catch (Exception e) {

View File

@@ -109,12 +109,7 @@ public class Server implements Runnable {
* @param client the client to disconnect
*/
public void disconnect(Client client) {
//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();
client.stop();
int index = clientIndex(client);
if (index != -1) {
removeIndex(index);
@@ -220,8 +215,8 @@ public class Server implements Runnable {
thread = null;
if (clients != null) {
for (int i = 0; i < clientCount; i++) {
disconnect(clients[i]);
while(clientCount>0){
disconnect(clients[0]);
}
clientCount = 0;
clients = null;