예제 #1
0
        public void TestMultipleConcurrentCallsShouldNotThrowException()
        {
            JsonRpcServer server = new JsonRpcServer("nats://127.0.0.1", 5000);
            List <Task>   tasks  = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                var task = Task.Run(() =>
                {
                    JsonRpcRequest request = new JsonRpcRequest
                    {
                        Method     = "test:channel",
                        Id         = Guid.NewGuid().ToString(),
                        Parameters = new Dictionary <string, string>
                        {
                            { "data", "ping" }
                        }
                    };

                    //server.ServeAsync(request).GetAwaiter().GetResult();
                });
                tasks.Add(task);
            }

            Assert.DoesNotThrow(() => { Task.WaitAll(tasks.ToArray()); });
            server.Dispose();
        }
예제 #2
0
        public void TestDisposedServiceThrowsException()
        {
            JsonRpcServer server = new JsonRpcServer("nats://127.0.0.1", 5000);

            server.Dispose();
            JsonRpcRequest request = new JsonRpcRequest
            {
                Method     = "test:channel",
                Id         = Guid.NewGuid().ToString(),
                Parameters = new Dictionary <string, string>
                {
                    { "data", "ping" }
                }
            };

            Assert.Throws <ObjectDisposedException>(() => server.Serve(request));
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("JSON RPC SimpleServer\n");

            _server = new JsonRpcServer();

            _listener = new TcpListener(IPAddress.Any, 11000);
            _listener.Start();

            // Accept first client connection
            _listener.BeginAcceptTcpClient(AcceptClient, null);

            Console.WriteLine($"Listening on port 11000");
            Console.WriteLine("Press ENTER to stop\n");
            Console.ReadLine();

            _listener.Stop();
            _server.Dispose();
        }