Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            //should run RSocketDemo.Server first.
            Console.WriteLine($"Enter any key to launch the client...");
            Console.ReadKey();
            Console.WriteLine($"Client started...{Thread.CurrentThread.ManagedThreadId}");

            ClientSocketTransport socketTransport = new ClientSocketTransport("127.0.0.1", 8888);

            _client = new RSocketDemoClient(socketTransport, new RSocketOptions()
            {
                InitialRequestSize = int.MaxValue, KeepAlive = TimeSpan.FromSeconds(60), Lifetime = TimeSpan.FromSeconds(120)
            });
            await _client.ConnectAsync(data : Encoding.UTF8.GetBytes("setup.data"), metadata : Encoding.UTF8.GetBytes("setup.metadata"));

            while (true)
            {
                await RequestFireAndForgetTest();

                ReadKey();

                await RequestResponseTest();

                ReadKey();

                await RequestStreamTest();

                ReadKey();
                await RequestStreamTest1();

                ReadKey();

                await RequestChannelTest();

                ReadKey();
                await RequestChannelTest(metadata : "echo");

                ReadKey();
                await RequestChannelTest1();

                ReadKey();

                await RequestChannelTest_Backpressure();                 //backpressure

                ReadKey();

                await ErrorTest();

                ReadKey();

                await RunParallel();

                ReadKey();

                Console.WriteLine("-----------------------------------over-----------------------------------");
                Console.ReadKey();
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Run RSocketDemo.Client and RSocketDemo.Server please.");
            Console.ReadKey();
            await Test();

            IPAddress  iP         = IPAddress.Parse("127.0.0.1");
            IPEndPoint iPEndPoint = new IPEndPoint(iP, 8888);

            SocketListenerFactory socketListenerFactory = new SocketListenerFactory();
            RSocketHost           host = new RSocketHost(socketListenerFactory, iPEndPoint, a =>
            {
                return(new EchoServer(a));
            });
            var hostTask = host.ExecuteAsync(CancellationToken.None);

            ClientSocketTransport socketTransport = await ClientSocketTransport.Create("tcp://127.0.0.1:8888/");

            _client = new EchoRSocketClient(socketTransport, new RSocketOptions()
            {
                InitialRequestSize = int.MaxValue
            });
            await _client.ConnectAsync();

            Console.ReadKey();
        }
Ejemplo n.º 3
0
 public void TestInitialize()
 {
     Loopback = new LoopbackTransport(DuplexPipe.ImmediateOptions, DuplexPipe.ImmediateOptions);
     Client   = new RSocketClient(Loopback);
     Server   = new RSocketServer(Loopback.Beyond);
     Client.ConnectAsync().Wait();
     Server.ConnectAsync().Wait();
     StringClient = new RSocketClient.ForStrings(Client);
 }
Ejemplo n.º 4
0
        //TODO Connection Cleanup on Unsubscribe/failure/etc
        //TODO General Error handling -> OnError

        static async Task Main(string[] args)
        {
            var loopback = new LoopbackTransport();
            var server   = new EchoServer(loopback.Beyond);
            await server.ConnectAsync();

            //var client = new RSocketClient(new SocketTransport("tcp://localhost:9091/"), new RSocketOptions() { InitialRequestSize = 3 });
            //var client = new RSocketClient(new WebSocketTransport("ws://localhost:9092/"), new RSocketOptions() { InitialRequestSize = 3 });
            var client = new RSocketClient(loopback, new RSocketOptions()
            {
                InitialRequestSize = int.MaxValue
            });
            await client.ConnectAsync();


            Console.WriteLine("Requesting Raw Protobuf Stream...");

            var persondata = new Person()
            {
                Id = 1234, Name = "Someone Person", Address = new Address()
                {
                    Line1 = "123 Any Street", Line2 = "Somewhere, LOC"
                }
            };
            var personmetadata = new Person()
            {
                Id = 567, Name = "Meta Person", Address = new Address()
                {
                    Line1 = "", Line2 = ""
                }
            };

            //Make a Raw binary call just to show how it's done.
            //var stream = client.RequestStream(
            //	resultmapper: result => (Data: ProtobufNetSerializer.Deserialize<Person>(result.Data), Metadata: ProtobufNetSerializer.Deserialize<Person>(result.Metadata)),
            //	data: ProtobufNetSerializer.Serialize(persondata), metadata: ProtobufNetSerializer.Serialize(personmetadata));

            var stream = client.RequestStream(ProtobufNetSerializer.Serialize(persondata), ProtobufNetSerializer.Serialize(personmetadata));

            await stream.ForEachAsync(persons => Console.WriteLine($"RawDemo.OnNext===>[{ProtobufNetSerializer.Deserialize<Person>(persons.Metadata)}]{ProtobufNetSerializer.Deserialize<Person>(persons.Data)}"));


            Console.WriteLine("\nRequesting String Serializer Stream...");

            await client.RequestStream("A Demo Payload")
            .ForEachAsync(result => Console.WriteLine($"StringDemo.OnNext===>{result}"));

            Console.ReadKey();

            //var sender = from index in Observable.Interval(TimeSpan.FromSeconds(1)) select new Person() { Id = (int)index, Name = $"Person #{index:0000}" };
            //using (personclient.RequestChannel(obj).Subscribe(
            //	onNext: value => Console.WriteLine($"RequestChannel.OnNext ===>{value}"), onCompleted: () => Console.WriteLine($"RequestChannel.OnComplete!")))
            //{
            //	Console.ReadKey();
            //}
        }
Ejemplo n.º 5
0
        static async Task Main1(string[] args)
        {
            //Create a new Client.
            var client = new RSocketClient(
                new WebSocketTransport("ws://localhost:9092/"));
            //	new SocketTransport("tcp://localhost:9091/"));

            //Bind a Service to this Client.
            var service = new EchoService.EchoServiceClient(client);

            //Connect to a Server and establish communications.
            await client.ConnectAsync();

            //Make a service method call with no return to the server.
            await service.FireAndForget(Value.ForString($"{nameof(service.FireAndForget)}: Calling service..."));

            //Make a service method call returning a single value.
            var result = await service.RequestResponse(Value.ForString($"{nameof(service.RequestResponse)}: Calling service..."));

            Console.WriteLine($"Sample Result: {result.StringValue}");


            //C# 8.0: Change the target language version to see IAsyncEnumerable iteration using built-in language constructs. (Project -> Properties -> Build -> Advanced -> Language Version)
#if CSHARP8
            //Make a service call and asynchronously iterate the returning values.
            var stream = service.RequestStream(Value.ForString($"{nameof(service.RequestStream)}: Calling service..."));
            await foreach (var value in stream)
            {
                Console.WriteLine($"Stream Result: {value.StringValue}");
            }
            Console.WriteLine("Stream Done");


            //Make a service call taking asynchronous values and asynchronously iterate the returning values.
            var channel = service.RequestChannel(GenerateValues());
            await foreach (var value in channel)
            {
                Console.WriteLine($"Channel Result: {value.StringValue}");
            }
            Console.WriteLine("Channel Done");
#else
            //Make a service call and asynchronously iterate the returning values.
            var stream = service.RequestStream(Value.ForString($"{nameof(service.RequestStream)}: Calling service..."));
            await ForEach(stream, value => Console.WriteLine($"Stream Result: {value.StringValue}"), () => Console.WriteLine("Stream Done"));


            //Make a service call taking asynchronous values and asynchronously iterate the returning values.
            var channel = service.RequestChannel(GenerateValues());
            await ForEach(channel, value => Console.WriteLine($"Channel Result: {value.StringValue}"), () => Console.WriteLine("Channel Done"));

            //Wait for a keypress to end session.
            { Console.WriteLine($"Press any key to continue..."); Console.ReadKey(); }
#endif
        }
Ejemplo n.º 6
0
        static async Task Main(string[] args)
        {
            var transport = new LoopbackTransport();
            //	new WebSocketTransport("ws://localhost:9092/"));
            //	new SocketTransport("tcp://localhost:9091/")

            var client  = new RSocketClient(transport);
            var service = new EchoService.EchoServiceClient(client);

            var server   = new RSocketServer(transport.Beyond);
            var producer = new MyEchoServer(server);

            //TODO ASK: Should these be present in the generated methods to allow one-line construction?
            await server.ConnectAsync();

            await client.ConnectAsync();

            //await service.FireAndForget(Value.ForString("Fire and Forget Test Requrest"));
            //Console.WriteLine($"{nameof(service.FireAndForget)}() => void");

            var responseresult = await service.RequestResponse(Value.ForString("Request Response Test Requrest"));

            Console.WriteLine($"{nameof(service.RequestResponse)}() => {responseresult.StringValue}");


            var streamresults = await service.RequestStream(Value.ForString("Test Stream Request"))
                                .ToListAsync();                         //Collect all of the results. In C#8, this can be an async foreach - nice!

            streamresults.ForEach(result => Console.WriteLine($"{nameof(service.RequestStream)}() => {result.StringValue}"));


            var channelresults = await service.RequestChannel((
                                                                  from value in Enumerable.Range(1, 3) select Value.ForString($"Test Channel Value {value}")
                                                                  ).ToAsyncEnumerable()).ToListAsync();

            //Wait for a keypress to end session.
            { Console.WriteLine($"Press any key to continue..."); Console.ReadKey(); }
        }
Ejemplo n.º 7
0
 public async Task ConnectAsync()
 {
     await client.ConnectAsync(options, metadata : writeSetupMetadata());
 }
Ejemplo n.º 8
0
 public void TestInitialize()
 {
     Loopback = new Transports.LoopbackTransport(DuplexPipe.ImmediateOptions, DuplexPipe.ImmediateOptions);
     Server   = new TestServer(Loopback);
     Server.Connect();
     _Client = new Lazy <RSocketClient>(() => { var rsocket = new RSocketClient(Loopback); rsocket.ConnectAsync().Wait(); return(rsocket); });
 }