コード例 #1
0
        public Task ConnectAsync()
        {
            Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Path, Parameters);

            _client = new WebsocketClient(wsUri);
            _client.MessageReceived.Subscribe(Listen);
            _client.DisconnectionHappened.Subscribe(info =>
            {
                if (info.Type != DisconnectionType.ByUser)
                {
                    CloseHandler();
                }
            });

            var token = new CancellationTokenSource(ConnectTimeout).Token;

            token.ThrowIfCancellationRequested();
            try
            {
                _client.Start().Wait(token);
            }
            catch (Exception e)
            {
                if (e is OperationCanceledException)
                {
                    throw new TimeoutException();
                }
                throw e;
            }
            return(Task.CompletedTask);
        }
コード例 #2
0
ファイル: SocketIO.cs プロジェクト: Ragueel/UnityRealtimeChat
 public async Task ConnectAsync()
 {
     Uri wsUri = UrlConverter.HttpToWs(ServerUri, _options);
     await Socket.ConnectAsync(wsUri, new WebSocketConnectionOptions
     {
         ConnectionTimeout = _options.ConnectionTimeout
     });
 }
コード例 #3
0
 public async Task ConnectAsync()
 {
     _tokenSource = new CancellationTokenSource();
     Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Path, Parameters);
     if (_socket != null)
     {
         _socket.Dispose();
     }
     _socket = new ClientWebSocket();
     await _socket.ConnectAsync(wsUri, CancellationToken.None);
     Listen();
 }
コード例 #4
0
        public Task ConnectAsync()
        {
            _tokenSource = new CancellationTokenSource();
            Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Parameters);

            if (_socket != null)
            {
                _socket.Dispose();
            }
            _socket = new ClientWebSocket();
            bool executed = _socket.ConnectAsync(wsUri, CancellationToken.None).Wait(ConnectTimeout);

            if (!executed)
            {
                throw new TimeoutException();
            }
            Listen();
            return(Task.CompletedTask);
        }