Exemplo n.º 1
0
 private void PushLength(int length, ref PooledNetworkWriter writer)
 {
     // If length is single byte we write it
     if (length < 256)
     {
         writer.WriteByte((byte)length); // write the amounts of bytes that are coming up
     }
     else
     {
         // otherwise we write a two-byte length
         writer.WriteByte(k_LongLenMarker);      // mark larger size
         writer.WriteByte((byte)(length % 256)); // write the length modulo 256
         writer.WriteByte((byte)(length / 256)); // write the length divided by 256
     }
 }
Exemplo n.º 2
0
        public IEnumerator SendMany()
        {
            Task <RunNode.Result> task = RunNode.RunAsync("ReceiveManyMessages.js", 5_000);

            yield return(server.WaitForConnection);

            const int messageCount = 100;

            for (int i = 0; i < messageCount; i++)
            {
                using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
                {
                    writer.WriteByte((byte)i);
                    writer.WriteInt32(100);

                    ArraySegment <byte> segment = writer.ToArraySegment();

                    server.ServerSend(new List <int> {
                        1
                    }, Channels.DefaultReliable, segment);
                }
            }

            yield return(new WaitForSeconds(1));

            server.ServerDisconnect(1);

            yield return(new WaitUntil(() => task.IsCompleted));

            RunNode.Result result = task.Result;

            string expectedFormat         = "length: 5 msg: {0:X2} 64 00 00 00";
            IEnumerable <string> expected = Enumerable.Range(0, messageCount).Select(i => string.Format(expectedFormat, i));

            result.AssetTimeout(false);
            result.AssetOutput(expected.ToArray());
            result.AssetErrors();
        }