public void TestMultiplePacket() { var codec = new PacketCodec(); var a = new ConnectPacket(); var b = new DisconnectPacket(); var stream = new MemoryStream(); var writer = new BinaryWriter(stream); var data = ByteJoin.Combine(codec.Encode(a), codec.Encode(b)); var reader = new BinaryReader(new MemoryStream(data)); var iter = new PacketEnumerator(reader); // 1st packet { Assert.True(iter.MoveNext()); ConnectPacket p; Assert.True(iter.GetCurrent(out p)); Assert.Equal(a, p); } // 2nd packet { Assert.True(iter.MoveNext()); DisconnectPacket p; Assert.True(iter.GetCurrent(out p)); Assert.Equal(b, p); } // end of stream { Assert.False(iter.MoveNext()); } }
public void Flush() { var bytes = ByteJoin.Combine(queue); queue.Clear(); ws.Send(bytes); var now = TimeUtils.NowTimestamp; bandwidth.AddSent(bytes.Length, now); }
void Flush() { List <byte[]> cloned = null; lock (lockobj) { if (queue.Count == 0) { return; } cloned = new List <byte[]>(queue); queue.Clear(); } var bulk = ByteJoin.Combine(cloned); transport.Send(bulk); }