From 4928efa9475bc113d275b8b7c8d54255844be8b7 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Thu, 2 Apr 2020 02:48:40 +0200 Subject: [PATCH] Fix #59 (#102) Fix #59 --- src/serverP2P/ServerManagement.java | 1 - src/serverP2P/ServerManagementTCP.java | 5 +++++ src/serverP2P/ServerManagementUDP.java | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/serverP2P/ServerManagement.java b/src/serverP2P/ServerManagement.java index da3be22..5271c6f 100644 --- a/src/serverP2P/ServerManagement.java +++ b/src/serverP2P/ServerManagement.java @@ -66,7 +66,6 @@ public abstract class ServerManagement extends ServeErrors implements Runnable { stop = true; fileListWatcher.setStop(); ratioWatcher.setStop(); - sendUnregisterRequest(); closeSocket(); writeLog("Server stopped", LogLevel.Info); } diff --git a/src/serverP2P/ServerManagementTCP.java b/src/serverP2P/ServerManagementTCP.java index cbb337e..c8e4930 100644 --- a/src/serverP2P/ServerManagementTCP.java +++ b/src/serverP2P/ServerManagementTCP.java @@ -78,6 +78,11 @@ public class ServerManagementTCP extends ServerManagement { */ public void run() { writeLog("Server sucessfully started", LogLevel.Info); + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + sendUnregisterRequest(); + } + }); fileListWatcher = (FileWatcher)new FileWatcherTCP(logger, 10000, server, tracker, baseDirectory); // checking every 10 seconds Thread flwt = new Thread(fileListWatcher); flwt.start(); diff --git a/src/serverP2P/ServerManagementUDP.java b/src/serverP2P/ServerManagementUDP.java index 1dd7f53..7471241 100644 --- a/src/serverP2P/ServerManagementUDP.java +++ b/src/serverP2P/ServerManagementUDP.java @@ -73,6 +73,11 @@ public class ServerManagementUDP extends ServerManagement { */ public void run() { logger.writeUDP("Server sucessfully started", LogLevel.Info); + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + sendUnregisterRequest(); + } + }); fileListWatcher = (FileWatcher)new FileWatcherUDP(logger, 10000, server, tracker, baseDirectory); // checking every 10 seconds Thread flwt = new Thread(fileListWatcher); flwt.start();