Представляет отправителя сообщений по протоколу UDP.
Inheritance: Platform.Helpers.Disposables.DisposableBase
Beispiel #1
0
        public void Run(params string[] args)
        {
            Console.CancelKeyPress += OnCancelKeyPressed;

            try
            {
                using (var receiver = new UdpClient(8888))
                {
                    using (var sender = new UdpSender(7777))
                    {
                        Console.WriteLine("Welcome to terminal.");
                        Console.WriteLine("Press CTRL+C or enter empty line to stop terminal.");

                        while (_terminalRunning)
                        {
                            while (Console.KeyAvailable)
                            {
                                var line = Console.ReadLine();
                                if (!string.IsNullOrWhiteSpace(line))
                                    sender.Send(line);
                                else
                                    _terminalRunning = false;
                            }

                            while (receiver.Available > 0)
                            {
                                var message = receiver.ReceiveString();
                                if (!string.IsNullOrWhiteSpace(message))
                                    Console.WriteLine($"<- {message}");
                            }

                            Thread.Sleep(1);
                        }

                        Console.WriteLine("Terminal stopped.");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToRecursiveString());
            }

            Console.CancelKeyPress -= OnCancelKeyPressed;
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                LinksServerStoped = true;
            };

            //var links = new Links2();

            //var sequences = new Sequences(links);

            Console.WriteLine("Links slave server started.");

            using (var sender = new UdpSender(8888))
            {
                using (new UdpReceiver(7777, m =>
                {
                    if (!string.IsNullOrWhiteSpace(m))
                    {
                        Console.WriteLine($"R.M.: {m}");

                        if (m.EndsWith("?"))
                        {
                            m = m.Remove(m.Length - 1);
                            //sequences.Search(sender, m);
                        }
                    }
                }))
                {
                    while (!LinksServerStoped) Thread.Sleep(1);
                }
            }

            Console.WriteLine("Links slave server stopped.");
        }
Beispiel #3
0
 public MasterServer(ILinks<ulong> links, Sequences sequences, UdpSender sender)
 {
     _links = links;
     _sequences = sequences;
     _sender = sender;
 }