コード例 #1
0
        /// <summary>
        /// 连接到服务器
        /// </summary>
        /// <returns>状态</returns>
        public static int Connect()
        {
            int socketID   = -1;
            int qtSocketID = -1;
            List <ConnectInfo> connectInfos = new List <ConnectInfo>();

            m_connectService.GetConnects(connectInfos);
            int connectInfosSize = connectInfos.Count;

            for (int i = 0; i < connectInfosSize; i++)
            {
                ConnectInfo connectInfo = connectInfos[i];
                if (connectInfo.m_type == "主服务器")
                {
                    List <ProxyInfo> proxyInfos = new List <ProxyInfo>();
                    m_proxyService.GetProxyInfos(proxyInfos);
                    int proxyInfosSize = proxyInfos.Count;
                    for (int j = 0; j < proxyInfosSize; j++)
                    {
                        ProxyInfo pInfo = proxyInfos[i];
                        if (pInfo.m_use)
                        {
                            String ip = connectInfo.m_ip, proxyIP = "", proxyUserName = pInfo.m_name, proxyPwd = pInfo.m_pwd, proxyDomain = pInfo.m_domain;
                            int    proxyPort = pInfo.m_port;
                            if (pInfo.m_type == 3)
                            {
                                //CurlHttp *http = CurlHttp::GetInstance();
                                //http->GetIeProxySet(&proxyIP, &proxyPort);
                            }
                            else
                            {
                                proxyIP = pInfo.m_ip;
                            }
                            int cType = 0;
                            if (pInfo.m_type == 1 || pInfo.m_type == 3)
                            {
                                cType = 1;
                            }
                            else if (pInfo.m_type == 2)
                            {
                                cType = 3;
                            }
                            socketID   = BaseService.ConnectToServer(cType, ip, connectInfo.m_port, proxyIP, proxyPort, proxyUserName, proxyPwd, proxyDomain, 6);
                            qtSocketID = BaseService.ConnectToServer(cType, ip, connectInfo.m_port, proxyIP, proxyPort, proxyUserName, proxyPwd, proxyDomain, 6);
                            break;
                        }
                    }
                }
            }
            if (socketID > 0)
            {
                m_connectState                    = 1;
                m_loginService.SocketID           = socketID;
                m_indicatorService.SocketID       = socketID;
                m_quoteService.SocketID           = qtSocketID;
                m_securityService.SocketID        = socketID;
                m_chatService.SocketID            = socketID;
                m_indicatorLayoutService.SocketID = socketID;
                m_macroService.SocketID           = socketID;
                m_securityFilterService.SocketID  = socketID;
                m_userSecurityService.SocketID    = socketID;
                m_userSessionService.SocketID     = socketID;
            }
            return(socketID);
        }