Exemple #1
0
        public async Task ConnectAsyncTaskTest()
        {
            try
            {
                wsProtocol.Listen();
                WebSocketProtocol ipvClient = this.CreateWSClientProtocol();
                var wsSocket = await ipvClient.ConnectAsync(serverAddress, PORT);

                Assert.IsNotNull(wsSocket);
                Assert.IsTrue(wsSocket.Connected);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
Exemple #2
0
        public void ConnectAsyncCallbackTest()
        {
            ManualResetEventSlim mevent = new ManualResetEventSlim(false);

            mevent.Reset();
            try
            {
                wsProtocol.Listen();
                WebSocketProtocol ipvClient = this.CreateWSClientProtocol();
                bool connected = false;
                ipvClient.ConnectAsync((socket) =>
                {
                    connected = socket.Connected;
                    mevent.Set();
                }, serverAddress, PORT);
                mevent.Wait(1000);
                Assert.IsTrue(condition: connected, message: "A connection could not be established.");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }