示例#1
0
        static void Main(string[] args)
        {
            var port = 1055;
            if (args.Length > 0)
                port = int.Parse(args[0]);

            var server = new ReactiveListener(port);

            server.Connections.Subscribe(socket =>
            {
                Console.WriteLine("New socket connected {0}", socket.GetHashCode());

                var protocol = new StringChannel(socket);

                // Here we hook the "echo" prototocol
                protocol.Receiver.Subscribe(
                    s => { Console.Write(s); protocol.SendAsync(s).Wait(); }, 
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                socket.Disconnected += (sender, e) => Console.WriteLine("Socket disconnected {0}", sender.GetHashCode());
                socket.Disposed += (sender, e) => Console.WriteLine("Socket disposed {0}", sender.GetHashCode());
            });

            server.Start();

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            var port = 1055;

            if (args.Length > 0)
            {
                port = int.Parse(args[0]);
            }

            var server = new ReactiveListener(port);

            server.Connections.Subscribe(socket =>
            {
                Console.WriteLine("New socket connected {0}", socket.GetHashCode());

                var protocol = new StringChannel(socket);

                // Here we hook the "echo" prototocol
                protocol.Receiver.Subscribe(
                    s => { Console.Write(s); protocol.SendAsync(s).Wait(); },
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                socket.Disconnected += (sender, e) => Console.WriteLine("Socket disconnected {0}", sender.GetHashCode());
                socket.Disposed     += (sender, e) => Console.WriteLine("Socket disposed {0}", sender.GetHashCode());
            });

            server.Start();

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    throw new ArgumentException("Usage: reactiveclient host [port]");
                }

                var host = args[0];
                var port = 1055;

                if (args.Length > 1)
                {
                    port = int.Parse(args[1]);
                }

                var client   = new ReactiveClient(host, port);
                var protocol = new StringChannel(client);

                protocol.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(
                    s => Console.Write(s),
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                client.ConnectAsync().Wait();

                string line = null;

                while ((line = Console.ReadLine()) != "")
                {
                    if (line == "r")
                    {
                        Console.WriteLine("Reconnecting...");
                        client.Disconnect();
                        client.ConnectAsync().Wait();
                        Console.WriteLine("IsConnected = {0}", client.IsConnected);
                    }
                    else
                    {
                        Console.WriteLine("Sending");
                        protocol.SendAsync(line);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed: {0}", e);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                    throw new ArgumentException("Usage: reactiveclient host [port]");

                var host = args[0];
                var port = 1055;

                if (args.Length > 1)
                    port = int.Parse(args[1]);

                var client = new ReactiveClient(host, port);
                var protocol = new StringChannel(client);

                protocol.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(
                    s => Console.Write(s),
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                client.ConnectAsync().Wait();

                string line = null;

                while ((line = Console.ReadLine()) != "")
                {
                    if (line == "r")
                    {
                        Console.WriteLine("Reconnecting...");
                        client.Disconnect();
                        client.ConnectAsync().Wait();
                        Console.WriteLine("IsConnected = {0}", client.IsConnected);
                    }
                    else
                    {
                        Console.WriteLine("Sending");
                        protocol.SendAsync(line);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed: {0}", e);
            }
        }