Esempio n. 1
0
        async partial void StartButtonPressed(NSObject sender)
        {
            if (ServerStatus == ServerStatus.Stopped)
            {
                UpdateServerStatus(ServerStatus.Starting);
                Settings = new ConnectionSettings(NameInput.StringValue, PortInput.IntValue,
                                                  BufferSizeInput.IntValue);
                if (!Settings.Valid)
                {
                    DisplayError("One of the input values is incorrect!");
                    UpdateServerStatus(ServerStatus.Stopped);
                    return;
                }
                ServerCancellationTokenSource = new CancellationTokenSource();
                ServerCancellationTokenSource.Token.Register(Stop);
                Server = new TcpListener(Settings.IpAddress, Settings.Port);
                if (!Start())
                {
                    return;
                }
                UpdateServerStatus(ServerStatus.Started);
                await ListenAsync(ServerCancellationTokenSource.Token);
            }
            else if (ServerStatus == ServerStatus.Started)
            {
                UpdateServerStatus(ServerStatus.Stopping);
                await SayGoodbye();

                ServerCancellationTokenSource.Cancel();
                UpdateServerStatus(ServerStatus.Stopped);
            }
        }
        public async Task ShutdownServer()
        {
            foreach (var client in Clients)
            {
                await StopSession(client.Value);
            }

            Listener.Stop();
            ServerCancellationTokenSource.Cancel();
        }