看板 C_Sharp 關於我們 聯絡資訊
我看到網路上的範例 建立連線這樣寫 socket.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), socket); connectDone.WaitOne(); Reset(); 功力太弱看不懂... 我再去看它裡面有一各ConnectCallback方法 看樣子會呼叫到這各方法 為何要寫一各client.EndConnect(ar); 不是要建立連線嗎 為何要結束擱置的非同步連接要求 private void ConnectCallback(IAsyncResult ar) //AsyncCallback 使用 IAsyncResult 介面,來取得非同步作業的狀態 { Socket client = null; try { // Retrieve the socket from the state object. client = (Socket)ar.AsyncState; // Complete the connection. client.EndConnect(ar); // Signal that the connection has been made. connectDone.Set(); } catch (Exception e) { Disconnect(); //throw(new ApplicationException("Unable to connect to " + // client.RemoteEndPoint.ToString(), e)); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.154.192.30