Example #1
0
        public static DistCacheClient Create(DistCacheClientConfig config)
        {
            TcpClient  tcp = null;
            IPEndPoint toTry;
            Dictionary <IPEndPoint, bool> invalidEndPoints = new Dictionary <IPEndPoint, bool>();

            while ((toTry = config.GetOrderedServerIpEndPoint().FirstOrDefault(i => !invalidEndPoints.ContainsKey(i))) != null)
            {
                try
                {
                    tcp = SocketHandler.CreateSocket(toTry, config);
                }
                catch (Exception ex)
                {
                    tcp = null;
                    invalidEndPoints[toTry] = true;
                }
                if (tcp != null)
                {
                    break;
                }
            }
            if (tcp != null)
            {
                return(new DistCacheClient(tcp, config));
            }
            throw new Exception("could not connect to any node");
        }
Example #2
0
 private DistCacheClient(TcpClient tcp, DistCacheClientConfig config)
 {
     using (var hs = new ClientHandShakeHandler(tcp, config, this.ClientId))
     {
         hs.Initiate();
         if (!hs.VerifyConnection())
         {
             throw new Exception("invalid log in or connection error");
         }
         this.ProtocolHandler = new ClientProtocolHandler(hs);
         this.ProtocolHandler.Initiate();
     }
 }