Exemplo n.º 1
0
        private async Task ConnectAsyncInternal(CancellationTokenSource cts = null)
        {
            if (Connected)
            {
                throw new InvalidOperationException();
            }

            _client = new System.Net.Sockets.TcpClient();
            if (cts == null)
            {
                await _client.ConnectAsync(_info.IpAddress, _info.Port);
            }
            else
            {
                try
                {
                    await _client.ConnectAsync(_info.IpAddress, _info.Port).WithCancellation(cts.Token);
                }
                catch (OperationCanceledException)
                {
                    Logger.LogWarning("Connecting interrupted");
                    return;
                }
            }

            Logger.Log($"Connected with {_info.IpAddress}:{_info.Port}");
        }
Exemplo n.º 2
0
        protected override void HandleResponse(OperationResponse response)
        {
            switch (response.ResponseCode)
            {
            case OperationResponseCode.InvalidProtocol:
            case OperationResponseCode.InvalidLogin:
            case OperationResponseCode.InvalidPassword:
                Logger.LogError(response.ResponseCode.ToString());
                break;

            case OperationResponseCode.HandshakeSuccess:
                Logger.Log(response.ResponseCode.ToString());
                break;

            case OperationResponseCode.AlreadyConnected:
                Logger.LogWarning(response.ResponseCode.ToString());
                break;
            }
        }