Ejemplo n.º 1
0
        public void With_WebSocket_CanWriteStringAsync()
        {
            var factories = new WebSocketFactoryCollection();

            factories.RegisterStandard(new WebSocketFactoryRfc6455());

            CancellationToken cancellationToken = CancellationToken.None;
            string            msg = "01";
            var handshake         = GenerateSimpleHandshake(factories);
            var ms = new MemoryStream();

            using (WebSocket ws = new WebSocketRfc6455(
                       ms,
                       new WebSocketListenerOptions {
                PingTimeout = Timeout.InfiniteTimeSpan
            },
                       new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1),
                       new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2),
                       handshake.Request,
                       handshake.Response,
                       handshake.NegotiatedMessageExtensions))
            {
                ws.WriteStringAsync(msg, cancellationToken).Wait(cancellationToken);
            }

            Assert.Equal(new byte[] { 1, 2, 48, 49, 128, 0, 136, 2, 3, 232 }, ms.ToArray());
        }
Ejemplo n.º 2
0
        public static void With_WebSocket_CanWriteStringAsync()
        {
            CancellationToken cancellationToken = CancellationToken.None;
            string            msg = "01";
            var handshake         = GenerateSimpleHandshake();
            var ms = new MemoryStream();

            using (WebSocket ws = new WebSocketRfc6455(ms, new WebSocketListenerOptions {
                PingTimeout = Timeout.InfiniteTimeSpan
            }, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2), handshake.Request, handshake.Response, handshake.NegotiatedMessageExtensions))
            {
                ws.WriteStringAsync(msg, cancellationToken).Wait(cancellationToken);
            }

            Console.WriteLine("Should be : 1, 2, 48, 49, 128, 0, 136, 2, 3, 232");
            byte[] result = ms.ToArray();
            Console.Write("Result :    " + string.Join(", ", result.Select(x => x.ToString())));

            Console.WriteLine();
        }