mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
Merge pull request #2466 from kfeuz/Issue2133
Adds disconnectEvent() to Server... merging and will make additions
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,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) {
|
||||
|
||||
@@ -109,8 +109,7 @@ public class Server implements Runnable {
|
||||
* @param client the client to disconnect
|
||||
*/
|
||||
public void disconnect(Client client) {
|
||||
//client.stop();
|
||||
client.dispose();
|
||||
client.stop();
|
||||
int index = clientIndex(client);
|
||||
if (index != -1) {
|
||||
removeIndex(index);
|
||||
@@ -216,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;
|
||||
|
||||
Reference in New Issue
Block a user