Exemplo n.º 1
0
        public async Task ShortLengthMaskedWorksViaManagedWebSocket()
        {
            var options    = new PipeOptions(useSynchronizationContext: false);
            var duplexPipe = DuplexPipe.CreateConnectionPair(options, options);

            var webSocket = WebSocket.CreateFromStream(new DuplexPipeStream(duplexPipe.Application.Input, duplexPipe.Application.Output), true, null, TimeSpan.FromSeconds(30));
            var writer    = new WebSocketFrameWriter();

            var payloadString = String.Join(String.Empty, Enumerable.Repeat("This is a test payload.", 25));
            var payloadBuffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes(payloadString));
            var header        = WebSocketHeader.CreateMasked(true, WebSocketOpcode.Binary, (ulong)payloadBuffer.Length);

            var protocolWriter = new ProtocolWriter(duplexPipe.Transport.Output);
            await protocolWriter.WriteAsync(writer, new WebSocketWriteFrame(header, payloadBuffer));

            var receiveBuffer = new Memory <byte>(new byte[payloadBuffer.Length]);
            await webSocket.ReceiveAsync(receiveBuffer, default);

            Assert.Equal(payloadString, Encoding.UTF8.GetString(receiveBuffer.ToArray()));
        }
Exemplo n.º 2
0
 public void SequenceLessThanMinimumPlusMaskReturnsFalse()
 {
     var reader      = new WebSocketFrameReader();
     var headerBytes = GetHeaderBytes(WebSocketHeader.CreateMasked(true, default, 64));