public static TcpConnection GetClient(string Hostname, int port, bool IsSecure)
        {
            TcpConnection cached = null;

            while (true)
            {
                lock (ConnectionCache)
                {
                    cached = ConnectionCache.FirstOrDefault(x => x.HostName == Hostname && x.port == port && x.IsSecure == IsSecure && x.TcpClient.Connected);

                    if (cached != null)
                    {
                        ConnectionCache.Remove(cached);
                    }
                }

                if (cached != null && !cached.TcpClient.Client.IsConnected())
                {
                    continue;
                }

                if (cached == null)
                {
                    break;
                }
            }

            if (cached == null)
            {
                cached = CreateClient(Hostname, port, IsSecure);
            }

            if (ConnectionCache.Where(x => x.HostName == Hostname && x.port == port && x.IsSecure == IsSecure && x.TcpClient.Connected).Count() < 2)
            {
                Task.Factory.StartNew(() => ReleaseClient(CreateClient(Hostname, port, IsSecure)));
            }

            return(cached);
        }
 public static void ReleaseClient(TcpConnection Connection)
 {
     Connection.LastAccess = DateTime.Now;
     ConnectionCache.Add(Connection);
 }
Ejemplo n.º 3
0
 public void SetConnection(TcpConnection Connection)
 {
     Connection.LastAccess = DateTime.Now;
     ProxyClient = Connection;
 }
 public static void ReleaseClient(TcpConnection Connection)
 {
     Connection.LastAccess = DateTime.Now;
     ConnectionCache.Add(Connection);
 }
Ejemplo n.º 5
0
 public void SetConnection(TcpConnection Connection)
 {
     Connection.LastAccess = DateTime.Now;
     ProxyClient           = Connection;
 }