コード例 #1
0
 public void ClientWebSocketTransportReadTest()
 {
     var websocket = new ClientWebSocket();
     var clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null);
     TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
     byte[] byteArray = new byte[10];
     args.SetBuffer(byteArray, 0, 10);
     clientWebSocketTransport.ReadAsync(args);
 }
コード例 #2
0
        public async Task ClientWebSocketTransportReadWithoutConnectTest()
        {
            var websocket = new ClientWebSocket();
            var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);
            var args = new TransportAsyncCallbackArgs();
            var byteArray = new byte[10];
            args.SetBuffer(byteArray, 0, 10);
            if (clientWebSocketTransport.ReadAsync(args))
            {
                while (!readComplete)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }

            await websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
        }
コード例 #3
0
        public void ReadWriteTest()
        {
            var websocket = new ClientWebSocket();
            // Set SubProtocol to AMQPWSB10
            websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10);
            Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix);
            websocket.ConnectAsync(uri, CancellationToken.None).Wait(CancellationToken.None);
            clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null);

            // Test Write API
            TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
            args.CompletedCallback = onWriteOperationComplete;
            args.SetBuffer(byteArray, 0, byteArray.Length);
            clientWebSocketTransport.WriteAsync(args);

            // Test Read API
            args.CompletedCallback = onReadOperationComplete;
            clientWebSocketTransport.ReadAsync(args);
        }
コード例 #4
0
        public void ReadWriteAfterAbortTest()
        {
            var websocket = new ClientWebSocket();
            // Set SubProtocol to AMQPWSB10
            websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10);
            Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix);
            websocket.ConnectAsync(uri, CancellationToken.None).Wait(CancellationToken.None);
            clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null);
            clientWebSocketTransport.Abort();

            try
            {
                TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
                args.SetBuffer(byteArray, 0, byteArray.Length);
                clientWebSocketTransport.WriteAsync(args);
                Assert.Fail("Did not throw object disposed exception");
            }
            catch(ObjectDisposedException)
            {

            }

            try
            {
                TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
                byte[] byteArray = new byte[10];
                args.SetBuffer(byteArray, 0, 10);
                clientWebSocketTransport.ReadAsync(args);
                Assert.Fail("Did not throw object disposed exception");
            }
            catch (ObjectDisposedException)
            {

            }
        }
コード例 #5
0
        public async Task ReadWriteTest()
        {
            var websocket = new ClientWebSocket();
            // Set SubProtocol to AMQPWSB10
            websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10);
            Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix);
            await websocket.ConnectAsync(uri, CancellationToken.None);
            clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);

            // Test Write API
            var args = new TransportAsyncCallbackArgs();
            args.CompletedCallback = onWriteOperationComplete;
            args.SetBuffer(byteArray, 0, byteArray.Length);
            clientWebSocketTransport.WriteAsync(args);

            // Test Read API
            args.CompletedCallback = onReadOperationComplete;
            if (clientWebSocketTransport.ReadAsync(args))
            {
                while (!readComplete)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }

            // Once Read operation is complete, close websocket transport
            // Test Close API
            await clientWebSocketTransport.CloseAsync(TimeSpan.FromSeconds(30));
        }
コード例 #6
0
 public async Task ReadAfterAbortTest()
 {
     var websocket = new ClientWebSocket();
     // Set SubProtocol to AMQPWSB10
     websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10);
     Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix);
     await websocket.ConnectAsync(uri, CancellationToken.None);
     clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);
     clientWebSocketTransport.Abort();
     var args = new TransportAsyncCallbackArgs();
     var byteArray = new byte[10];
     args.SetBuffer(byteArray, 0, 10);
     clientWebSocketTransport.ReadAsync(args);
 }
コード例 #7
0
        public async Task ReadAfterCloseTest()
        {
            var websocket = new ClientWebSocket();
            // Set SubProtocol to AMQPWSB10
            websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10);
            var uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix);
            await websocket.ConnectAsync(uri, CancellationToken.None);
            clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);
            await clientWebSocketTransport.CloseAsync(TimeSpan.FromSeconds(30));

            var args = new TransportAsyncCallbackArgs();
            var byteArray = new byte[10];
            args.SetBuffer(byteArray, 0, 10);
            args.CompletedCallback = onReadOperationComplete;
            clientWebSocketTransport.ReadAsync(args);
        }