【发布时间】:2012-09-19 17:55:08
【问题描述】:
我得到了一个代码,其中也涉及到一个异步套接字,这是我的初学者。我不知道为什么作为 BeginAccept 套接字的第二个参数的对象状态为空,老实说,我没有从 MSDN 中得到这个参数的使用。还有,为什么要从回调方法再次调用 BeginAccept?
public void Start()
{
this.mTcpListener.Start();
this.mTcpListener.BeginAcceptSocket(this.AcceptClient, null);
}
protected void AcceptClient(IAsyncResult ar)
{
if (this.mTcpListener != null)
{
System.Net.Sockets.Socket s = this.mTcpListener.EndAcceptSocket(ar);
Client c = new Client(this, s, this.GetFreePlayerID());
..some code for adding the client instance to collection....
this.mTcpListener.BeginAcceptSocket(this.AcceptClient, null);
}
}
【问题讨论】:
标签: c# networking asynchronous