void EndConnect(System.IAsyncResult iar)
 {
     m_clientSocket.EndConnect(iar);
     m_clientSocket.NoDelay = true;
     connectState           = ConnectGUI.ConnectionState.Connected;
     BeginReceiveData();
     Debug.Log("Client connected");
 }
 public void StartConnect()
 {
     m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     try
     {
         System.IAsyncResult result = m_clientSocket.BeginConnect("127.0.0.1", 10000, EndConnect, null);
         bool connectSuccess        = result.AsyncWaitHandle.WaitOne(System.TimeSpan.FromSeconds(10));
         if (!connectSuccess)
         {
             m_clientSocket.Close();
             Debug.LogError(string.Format("Client unable to connect. Failed"));
         }
     }
     catch (System.Exception ex)
     {
         Debug.LogError(string.Format("Client exception on beginconnect: {0}", ex.Message));
     }
     connectState = ConnectGUI.ConnectionState.AttemptingConnect;
 }
 void Start()
 {
     connectState = ConnectGUI.ConnectionState.NotConnected;
     m_readBuffer = new byte[1024];
 }