public override async Task ConnectAsync()
        {
            await base.ConnectAsync();

            if (_webSocketTransport != null)
            {
                _webSocketTransport.OnTextReceived   -= OnTextReceived;
                _webSocketTransport.OnBinaryReceived -= OnBinaryReceived;
                _webSocketTransport.OnAborted        -= OnAborted;
                _webSocketTransport.Dispose();
            }
            Uri uri = UriConverter.GetServerUri(true, ServerUri, EIO, Options.Path, Options.Query);

            _clientWebSocket = ClientWebSocketProvider();
            if (Options.ExtraHeaders != null)
            {
                foreach (var item in Options.ExtraHeaders)
                {
                    _clientWebSocket.SetRequestHeader(item.Key, item.Value);
                }
            }
            _webSocketTransport = new WebSocketTransport(_clientWebSocket, EIO)
            {
                ConnectionTimeout = Options.ConnectionTimeout
            };
            _webSocketTransport.OnTextReceived   = OnTextReceived;
            _webSocketTransport.OnBinaryReceived = OnBinaryReceived;
            _webSocketTransport.OnAborted        = OnAborted;
            Debug.WriteLine($"[Websocket] Connecting");
            await _webSocketTransport.ConnectAsync(uri).ConfigureAwait(false);

            Debug.WriteLine($"[Websocket] Connected");
        }
Ejemplo n.º 2
0
 public override void Dispose()
 {
     if (_Transport != null)
     {
         _Transport.Dispose();
     }
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (_Transport != null)
     {
         _Transport.Dispose();
     }
 }
Ejemplo n.º 4
0
        public void CloseConnection(string connectionId, bool keepAlive)
        {
            WebSocketTransport transport = null;

            if (keepAlive)
            {
                if (Connections.TryGetValue(connectionId, out transport))
                {
                    transport.Dispose();
                }
            }
            else
            {
                if (Connections.TryRemove(connectionId, out transport))
                {
                    transport.Dispose();
                }
            }
        }
Ejemplo n.º 5
0
        public async Task WebSocketTransport_SetsState()
        {
            var sock = new FauxSock();

            sock.RealState = WebSocketState.Open;
            var transport = new WebSocketTransport(sock);

            transport.Close();
            transport.Dispose();

            Assert.Equal(WebSocketState.Closed, sock.RealState);
        }
Ejemplo n.º 6
0
        public async Task WebSocketTransport_Connects()
        {
            var sock = new FauxSock();

            sock.RealState = WebSocketState.Open;
            var transport = new WebSocketTransport(sock);

            Assert.True(transport.IsConnected);

            transport.Close();
            transport.Dispose();
        }
Ejemplo n.º 7
0
 public virtual void Dispose()
 {
     _server.Dispose();
     _transport.Dispose();
 }