public void SendMessage (System.Object param) { try { //這是一個異步的創建鏈接,當鏈接創建成功時調用connectCallback方法 clientSocket.BeginConnect (ipAddress, hostPort, new AsyncCallback (connectCallback), param); } catch (Exception ex) { Debug.Log (ex.ToString ()); } } private void connectCallback (IAsyncResult asyncConnect) { if (!clientSocket.Connected) { closeSocket (); } else { clientSocket.EndConnect (asyncConnect); businessComm (asyncConnect.AsyncState); } }