请教各位大佬,关于socket异步接收数据的代码,不太理解BeginReceive和EndReceive在.net里实现的机制,想看.net里的源码,求指导!
代码如下:
//Receive回调
public void ReceiveCallback(IAsyncResult ar)
{
try
{
Socket socket = (Socket)ar.AsyncState;
int count = socket.EndReceive(ar);
recvStr = System.Text.Encoding.Default.GetString(readBuff, 0, count);
socket.BeginReceive(readBuff, 0, 1024, 0, ReceiveCallback, socket);
}
catch(SocketException ex)
{
Debug.Log("Socket Receive Fail " + ex.ToString());
}
}