コード例 #1
0
        internal void ConnectToServer(string strIP, ushort port)
        {
            if ((port == 0) || (port >= IPEndPoint.MaxPort - 4))
            {
                return;
            }
            CServer server = new CServer(strIP, port);

            server.Connect();
            //CercaVersione();
        }
コード例 #2
0
ファイル: ServersList.cs プロジェクト: biuken/eAnt
        /// <summary>
        /// Connect to the next server.
        /// </summary>
        private void m_ConnectToNextServers()
        {
            if (this.Count == 0)
            {
                return;
            }
            if (m_ActiveServer != null)
            {
                //we have a good connection
                m_DeleteFailedServers();
                return;
            }
            if (m_FailedConnetions <= 0)
            {
                m_FailedConnetions = Protocol.MaxParalelConnections;
            }
            if (m_ConnectionIndex >= this.Count)
            {
                //can not connect with any server, probably my connection is down, sleep some mintes and try again
                //and discount an error for all servers
                lock (InnerList.SyncRoot)
                {
                    foreach (CServer server in InnerList)
                    {
                        server.ResetFails();
                    }
                }
                Thread.Sleep(Protocol.RetryServerListConnection * 1000);
                m_ConnectionIndex = 0;
                if (ActiveServer != null)
                {
                    return;
                }
            }

            while ((m_FailedConnetions > 0) && (m_ConnectionIndex < this.Count))
            {
                CServer server = (CServer)this[m_ConnectionIndex];
                m_ConnectionIndex++;
                m_FailedConnetions--;
                server.Connect();
            }
        }
コード例 #3
0
ファイル: ServersList.cs プロジェクト: biuken/eAnt
        /// <summary>
        /// Connect to an specified server.
        /// </summary>
        /// <param name="ip">IP of the server.</param>
        /// <param name="port">Port of the server</param>
        /// <returns>Returns true if connection could be established.</returns>
        public bool ConnectToServer(uint ip, ushort port)
        {
            CServer server = this[ip, port];

            if (server != null)
            {
                if (m_ActiveServer != null)
                {
                    m_ActiveServer.Disconnect();
                    m_ActiveServer = null;
                }
                server.DisconectedByUser = true;               //set this flag to true to avoid reconnect to other servers if it fails
                server.Connect();
                return(true);
            }
            else
            {
                return(false);
            }
        }