コード例 #1
0
 public static bool Connect(int ServerIP, int Port)
 {
     Flush();
     m_ServerPort = Port;
     Engine.ValidateHandlers();
     m_Server     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     m_ServerIP   = new IPAddress((long)((ulong)ServerIP));
     m_ServerIPEP = new IPEndPoint(m_ServerIP, Port);
     Debug.Try("Connecting to game server '{0}'", m_ServerIPEP);
     try
     {
         IAsyncResult asyncResult = m_Server.BeginConnect(m_ServerIPEP, null, null);
         do
         {
             Engine.DrawNow();
         }while (!asyncResult.AsyncWaitHandle.WaitOne(10, false));
         m_Server.EndConnect(asyncResult);
     }
     catch (Exception exception)
     {
         Debug.FailTry();
         Debug.Error(exception);
         return(false);
     }
     Debug.EndTry();
     return(true);
 }
コード例 #2
0
 public static bool Connect()
 {
     m_ServerHost = NewConfig.ServerHost;
     m_ServerPort = NewConfig.ServerPort;
     try
     {
         Debug.Try("Parsing IP ( \"{0}\" )", m_ServerHost);
         m_ServerIP   = IPAddress.Parse(m_ServerHost);
         m_ServerIPEP = new IPEndPoint(m_ServerIP, m_ServerPort);
         Debug.EndTry("( {0} )", m_ServerIPEP);
     }
     catch
     {
         Debug.FailTry();
         try
         {
             Debug.Try("Resolving");
             IAsyncResult asyncResult = Dns.BeginResolve(m_ServerHost, null, null);
             do
             {
                 Engine.DrawNow();
             }while (!asyncResult.AsyncWaitHandle.WaitOne(10, false));
             IPHostEntry entry = Dns.EndResolve(asyncResult);
             if (entry.AddressList.Length == 0)
             {
                 Debug.FailTry("( AddressList is empty )");
                 return(false);
             }
             m_ServerIP   = entry.AddressList[0];
             m_ServerIPEP = new IPEndPoint(m_ServerIP, m_ServerPort);
             Debug.EndTry("( {0} )", m_ServerIPEP);
         }
         catch (Exception exception)
         {
             Debug.FailTry();
             Debug.Error(exception);
             return(false);
         }
     }
     Flush();
     Engine.ValidateHandlers();
     m_Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     Debug.Try("Connecting to login server '{0}'", m_ServerIPEP);
     try
     {
         IAsyncResult result2 = m_Server.BeginConnect(m_ServerIPEP, null, null);
         do
         {
             Engine.DrawNow();
         }while (!result2.AsyncWaitHandle.WaitOne(10, false));
         m_Server.EndConnect(result2);
     }
     catch (Exception exception2)
     {
         Debug.FailTry();
         Debug.Error(exception2);
         return(false);
     }
     Debug.EndTry();
     return(true);
 }