예제 #1
0
        public async void CommunicationDeviceSerializerBatchTest()
        {
            Regulus.Serialization.ISerializer serializer = new Regulus.Serialization.Dynamic.Serializer();
            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd;

            byte[] buf = serializer.ServerToClient(ServerToClientOpCode.LoadSoul, new Regulus.Remote.PackageLoadSoul()
            {
                EntityId = 1, ReturnType = false, TypeId = 1
            });

            await cd.Push(buf, 0, 1);

            await cd.Push(buf, 1, buf.Length - 1);

            byte[] recvBuf = new byte[buf.Length];
            await peer.Receive(recvBuf, 0, recvBuf.Length);

            await peer.Receive(recvBuf, 1, recvBuf.Length - 1);

            ResponsePackage responsePkg = serializer.Deserialize(recvBuf) as ResponsePackage;
            PackageLoadSoul lordsoulPkg = serializer.Deserialize(responsePkg.Data) as PackageLoadSoul;

            Assert.Equal(ServerToClientOpCode.LoadSoul, responsePkg.Code);
            Assert.Equal(1, lordsoulPkg.EntityId);
            Assert.False(lordsoulPkg.ReturnType);
            Assert.Equal(1, lordsoulPkg.TypeId);
        }
예제 #2
0
        public async System.Threading.Tasks.Task Test()
        {
            var listener = new Regulus.Network.Web.Listener();

            listener.Bind("http://127.0.0.1:12345/");
            var peers = new System.Collections.Concurrent.ConcurrentQueue <Web.Peer>();

            listener.AcceptEvent += peers.Enqueue;

            var connecter     = new Regulus.Network.Web.Connecter(new System.Net.WebSockets.ClientWebSocket());
            var connectResult = await connecter.ConnectAsync("ws://127.0.0.1:12345/");

            Xunit.Assert.True(connectResult);

            var ar = new Regulus.Utility.AutoPowerRegulator(new Utility.PowerRegulator());

            Web.Peer peer;
            while (!peers.TryDequeue(out peer))
            {
                ar.Operate();
            }
            IStreamable server = peer;
            var         serverReceiveBuffer = new byte[5];
            var         serverReceiveTask   = server.Receive(serverReceiveBuffer, 0, 5);
            IStreamable client          = connecter;
            var         clientSendCount = await client.Send(new byte[] { 1, 2, 3, 4, 5 }, 0, 5);

            var serverReceiveCount = await serverReceiveTask;

            Xunit.Assert.Equal(5, serverReceiveCount);
            Xunit.Assert.Equal(5, clientSendCount);
        }
예제 #3
0
 internal void Read(int size)
 {
     _Offset = 0;
     _Buffer = new byte[size];
     try
     {
         System.Threading.Tasks.Task <int> task = _Peer.Receive(_Buffer, _Offset, _Buffer.Length - _Offset);
         task.ContinueWith(t => _Readed(t.Result));
     }
     catch (SystemException e)
     {
         if (ErrorEvent != null)
         {
             ErrorEvent();
         }
     }
 }
예제 #4
0
 internal void Read(int size)
 {
     _Update = () => { };
     _Offset = 0;
     _Buffer = new byte[size];
     try
     {
         var task = _Peer.Receive(_Buffer, _Offset, _Buffer.Length - _Offset);
         task.ValueEvent += _Readed;
     }
     catch (SystemException e)
     {
         if (ErrorEvent != null)
         {
             ErrorEvent();
         }
     }
 }
예제 #5
0
        public void CommunicationDevicePushTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;

            cd.Push(sendBuf, 0, sendBuf.Length);
            System.Threading.Tasks.Task <int> receiveResult1 = peer.Receive(recvBuf, 0, 4);
            System.Threading.Tasks.Task <int> receiveResult2 = peer.Receive(recvBuf, 4, 6);

            int receiveCount1 = receiveResult1.GetAwaiter().GetResult();
            int receiveCount2 = receiveResult2.GetAwaiter().GetResult();

            Assert.AreEqual(4, receiveCount1);
            Assert.AreEqual(6, receiveCount2);
        }
예제 #6
0
        public async System.Threading.Tasks.Task CommunicationDevicePushTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;
            await cd.Push(sendBuf, 0, sendBuf.Length);


            int receiveCount1 = await peer.Receive(recvBuf, 0, 4);

            int receiveCount2 = await peer.Receive(recvBuf, 4, 5);

            int receiveCount3 = await peer.Receive(recvBuf, 9, 2);

            Assert.Equal(4, receiveCount1);
            Assert.Equal(5, receiveCount2);
            Assert.Equal(1, receiveCount3);
        }
예제 #7
0
 private void _Read()
 {
     System.Threading.Tasks.Task <int> task = _Peer.Receive(_ReadedByte, 0, 1);
     task.ContinueWith(t => _Readed(t));
 }
예제 #8
0
 private void _Read()
 {
     _ReadSize = 0;
     _Update   = () => { };
     _Peer.Receive(_ReadedByte, 0, 1).ValueEvent += _ReadDone;
 }