Exemplo n.º 1
0
        public async Task ConnectAsync(CancellationToken cancellationToken)
        {
            IClientSocket client = null;

            try
            {
                SocketOptionBuilder sb = SocketOptionBuilder.Instance;
                sb = sb.SetReadBufferSize(_options.BufferSize);
                sb = sb.SetWriteBufferSize(_options.BufferSize);
                if (!_options.NoDelay)
                {
                    sb = sb.SetDelay();
                }

                IPAddress ip;

                string ipStr = _options.Server;

                if (ipStr.IndexOf("localhost") > -1)
                {
                    ip = IPAddress.Parse("127.0.0.1");
                }
                else
                {
                    ip = IPAddress.Parse(ipStr);
                }

                if (_options.AddressFamily == AddressFamily.InterNetworkV6 || ip.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    sb = sb.UseIPv6();
                }
                sb = sb.SetIPEndPoint(new IPEndPoint(ip, _options.GetPort()));

                client = SocketFactory.CreateClientSocket(sb.Build());

                _stream = await((StreamClientSocket)client).ConnectAsync(InternalUserCertificateValidationCallback, LoadCertificates, !_options.TlsOptions.IgnoreCertificateRevocationErrors);

                Endpoint = client.Endpoint;
            }
            catch (Exception)
            {
                client?.Dispose();
                throw;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     _isDisposed = true;
     _client.Disconnect();
     _client.Dispose();
 }
Exemplo n.º 3
0
 public void Dispose()
 {
     ChannelManager.Current.Remove(_clientSocket.Endpoint);
     _clientSocket.Dispose();
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     ChannelManager.Instance.Remove(_clientSocket.Endpoint);
     _clientSocket.Dispose();
 }
Exemplo n.º 5
0
 public void Dispose()
 {
     _socket.Dispose();
 }
Exemplo n.º 6
0
 public void Dispose()
 {
     _clientSocket?.Dispose();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     _udpClient?.Dispose();
 }
Exemplo n.º 8
0
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     _clientSokcet.Dispose();
 }