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 listener = peerServices.CreateListenerFor(this);
     try {
         listener.Start();
         Dequeue().RunOnThread("Server");
         while (listener.Alive)
         {
             Thread.Sleep(1);
         }
     } finally {
         _stop = true;
     }
 }
 protected override void Run(IPeerServices peerServices)
 {
     using var listener = (peerServices.Required(nameof(peerServices))).CreateListenerFor(this);
     try {
         _ = listener.Start();
         listener.ExcessConnectionRejected  += Listener_ExcessConnectionRejected;
         listener.InactiveConnectionDropped += Listener_InactiveConnectionDropped;
         Dequeue().RunOnThread("DemoServer-DelayedResponses");
         while (listener.Alive)
         {
             Thread.Sleep(1);
         }
     } finally {
         _stop = true;
     }
 }
示例#4
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!");
                }
            }
        }
示例#5
0
 protected abstract void Run(IPeerServices peerServices);