public bool Start(string ipAddress, int port) { try { this.IPAddr = ipAddress; this.Port = port; if (KeepServerRunning) // Server already running ? { Stop(); } KeepServerRunning = true; socketServer = SocketServerHelper.Start(this.Port, this.IPAddr); acceptClients = Task.Run(() => AcceptClientsAsync()); removeIdleClients = Task.Run(() => RemoveClients()); return(true); } catch (Exception ex) { ExceptionHandler.HandleException(ex, "Error while initialising socket server"); return(false); } }
public bool Stop() { try { StartStopping(); SocketServerHelper.Stop(cancellation, socketServer); Debug.WriteLine("Closing socket server ... " + IpAndPort); SimpleFileWriter.WriteLineToEventFile(DirectoryName.EventLog, "Stopping socket server at " + IpAndPort); DisposeTasks(); return(true); } catch (Exception ex) { HandleError(StringManager.GetString("Error while stopping socket server: ") + ex.Message); return(false); } }