Пример #1
0
        public async Task SendBinary()
        {
            var room = await CreateRoom();

            Exception exception = null;

            var client = new IguagileClient();

            client.OnError     += e => { exception = e; };
            client.OnConnected += () => _ = client.SendAsync(_testData);
            client.OnReceived  += x =>
            {
                if (!_testData.SequenceEqual(x))
                {
                    var correctData   = string.Join(", ", _testData);
                    var incorrectData = string.Join(", ", x);
                    exception = new Exception($"data is not match \n({correctData})\n({incorrectData})");
                }

                client.Dispose();
            };

            await client.StartAsync(room);

            if (exception is TaskCanceledException)
            {
                exception = null;
            }

            Assert.IsNull(exception, exception?.Message);
        }
        public void Rpc_OtherClients()
        {
            var receivers = new RpcReceiver[ClientsNum];
            var clients   = new IguagileClient[ClientsNum];
            var poolOpen  = new Semaphore(0, ClientsNum);
            var poolClose = new Semaphore(0, ClientsNum);

            for (var i = 0; i < ClientsNum; i++)
            {
                var client = new IguagileClient();
                client.Open    += () => poolOpen.Release(1);
                client.Close   += () => poolClose.Release(1);
                client.OnError += e => Assert.Fail(e.Message);
                var receiver = new RpcReceiver(client, ClientsNum - 1);
                client.AddRpc(nameof(RpcReceiver.RpcMethod), receiver);
                client.Connect(ServerAddress, PortTcp, Protocol.Tcp);
                clients[i]   = client;
                receivers[i] = receiver;
            }

            for (var i = 0; i < ClientsNum; i++)
            {
                poolOpen.WaitOne();
            }

            for (var i = 0; i < ClientsNum; i++)
            {
                clients[i].Rpc(nameof(RpcReceiver.RpcMethod), RpcTargets.OtherClients, clients[i].UserId);
            }

            for (var i = 0; i < ClientsNum; i++)
            {
                poolClose.WaitOne();
            }
        }
        public void Connect_Tcp_WithValidAddress()
        {
            var client = new IguagileClient();

            client.Open += () => client.Disconnect();
            var pool = new Semaphore(0, 1);

            client.Close   += () => pool.Release(1);
            client.OnError += e => Assert.Fail(e.Message);
            client.Connect(ServerAddress, PortTcp, Protocol.Tcp);
            pool.WaitOne();
        }
 public RpcReceiver(IguagileClient client, int otherClientsNum)
 {
     _client          = client;
     _otherClientsNum = otherClientsNum;
 }