int n = theSockId.thisSocket.EndReceive(asyn);
m_socListener.BeginAccept(new AsyncCallback(OnClientConnect), null); : public void OnClientConnect(IAsyncResult asyn) { try { m_socWorker = m_socListener.EndAccept(asyn); WaitForData(m_socWorker); theNetwork.TheNetwork.gatewayType = Network.GatewayTypeE.TCP_GATEWAY; } : public void WaitForData(System.Net.Sockets.Socket soc) { try { if (pfnWorkerCallBack == null) pfnWorkerCallBack = new AsyncCallback(OnDataReceived); CSocketPacket theSocPkt = new CSocketPacket(); theSocPkt.thisSocket = soc; // now start to listen for any data... soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); } : public void OnDataReceived(IAsyncResult asyn) { CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState; //end receive... int n = theSockId.thisSocket.EndReceive(asyn);