示例#1
0
 public void StartServiceRpc(RpcService service)
 {
     lock (instance)
     {
         RpcTcpServer server = new RpcTcpServer(ip, service);
         server.Start();
         RpcServices.Add(server);
     }
 }
示例#2
0
        public void TcpConnection()
        {
            const int Program   = 12;
            const int Version   = 13;
            const int Procedure = 14;

            var receivedCallChannel = new Channel <ReceivedRpcCall>();

            void Dispatcher(ReceivedRpcCall call)
            {
                // To assert it on the main thread
                receivedCallChannel.Send(call);

                var pingStruct = new PingStruct();

                call.RetrieveCall(pingStruct);
                call.Reply(pingStruct);
            }

            var serverSettings = new ServerSettings
            {
                Logger = new TestLogger("TCP Server"),
                Port   = Port
            };

            using var server = new RpcTcpServer(this.ipAddress, Program, new[] { Version }, Dispatcher, serverSettings);
            server.Start();

            for (int i = 0; i < 10; i++)
            {
                var clientSettings = new ClientSettings
                {
                    Port   = Port,
                    Logger = new TestLogger("TCP Client")
                };

                using var client = new RpcTcpClient(this.ipAddress, Program, Version, clientSettings);
                var argument = new PingStruct {
                    Value = i
                };
                var result = new PingStruct();

                client.Call(Procedure, Version, argument, result);

                Assert.That(receivedCallChannel.TryReceive(TimeSpan.FromSeconds(10), out ReceivedRpcCall receivedCall));
                Assert.That(receivedCall.Procedure, Is.EqualTo(Procedure));
                Assert.That(receivedCall.Version, Is.EqualTo(Version));

                Assert.That(argument.Value, Is.EqualTo(result.Value));
            }
        }
示例#3
0
        public void ServerShutdownWithoutException()
        {
            const int Program = 12;
            const int Version = 13;

            var serverSettings = new ServerSettings
            {
                Logger = new TestLogger("TCP Server"),
                Port   = Port
            };

            var server = new RpcTcpServer(this.ipAddress, Program, new[] { Version }, call => { }, serverSettings);

            Assert.DoesNotThrow(() => server.Dispose());
        }
示例#4
0
        protected ServerStub(
            Protocol protocol,
            IPAddress ipAddress,
            int program,
            int[] versions,
            ServerSettings serverSettings = default)
        {
            if (ipAddress == null)
            {
                throw new ArgumentNullException(nameof(ipAddress));
            }

            if ((versions == null) || (versions.Length == 0))
            {
                throw new ArgumentNullException(nameof(versions));
            }

            if (protocol.HasFlag(Protocol.Tcp))
            {
                this.rpcTcpServer = new RpcTcpServer(
                    ipAddress,
                    program,
                    versions,
                    this.DispatchReceivedCall,
                    serverSettings);
            }

            if (protocol.HasFlag(Protocol.Udp))
            {
                this.rpcUdpServer = new RpcUdpServer(
                    ipAddress,
                    program,
                    versions,
                    this.DispatchReceivedCall,
                    serverSettings);
            }
        }