Пример #1
0
        public void TypedSend()
        {
            using var sc  = new ServerClientPair <RpcServerWithType <LobbyExecutor, IPlayerToLobby, ILobbyToPlayer>, RpcClientWithType <SimplePlayerExecutor, ILobbyToPlayer, IPlayerToLobby> >();
            using var evt = new ManualResetEvent(false);
            this.evt      = evt;
            EndPoint ep = null;

            sc.server.ClientConnected += (sender, e) =>
            {
                Log($"Server connected to {e.Value}");
                ep = e.Value;
                evt.Set();
            };

            sc.Start();
            evt.WaitOne();
            evt.Reset();

            sc.client.Invoker.ChangeRoom("Lobby");
            evt.WaitOne();
            evt.Reset();

            sc.server.InvokeTo(ep).OnPlayerJoined("Player1", "Lobby", 0);
            evt.WaitOne();
            evt.Reset();
        }
Пример #2
0
        public void SendData()
        {
            using var sc  = new ServerClientPair <RpcServer, RpcClient>();
            using var evt = new ManualResetEvent(false);
            EndPoint ep = null;

            sc.server.ClientConnected += (sender, e) =>
            {
                Log($"Server connected to {e.Value}");
                ep = e.Value;
                evt.Set();
            };
            sc.server.ReceivedData += (sender, e) =>
            {
                Log($"Server read from {e.V1} {e.V2.FuncName}, {e.V2.Parameters.Length}");
                Assert.Equal("Test", e.V2.FuncName);
                Assert.Equal(3, e.V2.Parameters.Length);
                evt.Set();
            };
            sc.client.ReceivedData += (sender, e) =>
            {
                Log($"Client read from {e.V1} {e.V2.FuncName}, {e.V2.Parameters.Length}");
                Assert.Equal("Test1", e.V2.FuncName);
                Assert.Equal(2, e.V2.Parameters.Length);
                evt.Set();
            };

            sc.Start();
            evt.WaitOne();
            evt.Reset();

            sc.client.Send("Test", new object[] { 1, 2, 3 });
            evt.WaitOne();
            evt.Reset();

            sc.server.Send(ep, "Test1", new object[] { 1, 2 });
            evt.WaitOne();
            evt.Reset();
        }
Пример #3
0
 public void Connect()
 {
     using var sc = new ServerClientPair <RpcServer, RpcClient>();
     sc.Start();
 }