示例#1
0
        public async Task CloseRepository()
        {
            if (WebSocketConnection != null)
            {
                WebSocketConnection.OnClose -= WebSocketConnection_OnClose;
                await WebSocketConnection.DisconnectAsync();

                WebSocketConnection = null;
            }
        }
示例#2
0
        public async Task ConnectDisconnect_ValidStatusAndInvokesConnectionEvents()
        {
            using ServerWebSocketConnection server = WebSocketServer.CreateServer(TEST_CONNECTION_PORT);
            bool connected = false;
            bool serverSideDisconnected = false, clientSideDisconnected = false;

            server.OnClientConnected += (o, a) => connected = true;
            server.OnClose           += (o, a) => serverSideDisconnected = true;
            _ = Task.Run(server.RunServerLoop);
            using WebSocketConnection client = await WebSocketClient.ConnectAsync(TEST_CONNECTION_URI);

            client.OnClose += (o, a) => clientSideDisconnected = true;
            Assert.IsTrue(connected);
            Assert.IsFalse(serverSideDisconnected);
            Assert.IsFalse(clientSideDisconnected);
            await client.DisconnectAsync();

            Assert.IsTrue(serverSideDisconnected);
            Assert.IsTrue(clientSideDisconnected);
        }
示例#3
0
 public void Disconnect()
 {
     socketConnection.DisconnectAsync();
 }