protected override void Run(IPeerServices peerServices)
        {
            using var client          = peerServices.GetClient("localhost", 8080);
            client.ConnectionStopped += (_) => _brokenConnection = true;
            var liveness = new ClientLivenessListener(client);

            while (!_source.IsCancellationRequested && liveness.Alive && !_brokenConnection)
            {
                Console.WriteLine();
                Console.Write(Prompt);
                while (!Console.KeyAvailable)
                {
                    if (!liveness.Alive || _brokenConnection)
                    {
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("Lost connection with server! Abandoning...");
                        Console.WriteLine();
                        return;
                    }
                }
                var command = Console.ReadLine();
                if (command == null || command.FirstOrDefault() == 'x')
                {
                    break;
                }
                var channel = client.AllocateChannel(this);
                channel.SendAsync(ToMessage(AsUTF8Bytes(command), isLast: true).DataList).Wait();
            }
        }
Пример #2
0
        protected override void Run(IPeerServices peerServices)
        {
            using var client = peerServices.GetClient("localhost", 8080);
            var liveness = new LivenessListener(client, this);

            while (!Source.IsCancellationRequested)
            {
                Console.WriteLine();
                Console.Write(Prompt);
                while (!Console.KeyAvailable)
                {
                    if (!liveness.Alive)
                    {
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("Lost connection with server! Abandoning...");
                        Console.WriteLine();
                        return;
                    }
                }
                var command = Console.ReadLine();
                if (command == null || command.FirstOrDefault() == 'x')
                {
                    break;
                }
                var channel = client.AllocateChannel(this);
                if (command == "w")
                {
                    SendPing(channel, visible: true);
                }
                else
                {
                    throw new NotImplementedException("Need to implement Send File feature!");
                }
            }
        }