我正在按照网站http://www.codeproject.com/Articles/463947/Working-with-Sockets-in-Csharp上的示例来构建套接字程序。
我只是想知道在下面的代码下acceptcallback 的替代品是什么。
Socket sListener;
SocketPermission sPermission = new SocketPermission(NetworkAccess.Accept,
TransportType.Tcp, "", SocketPermission.AllPorts);
sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPHostEntry ipHost = Dns.GetHostEntry("");
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndP = new IPEndPoint(ipAddr, 4510);
sListener.Bind(ipEndP);
sListener.Listen(10);
//error below this
AsyncCallback aCallback = new AsyncCallback(AcceptCallback);
sListener.BeginAccept(aCallback, sListener);
....
我在网上搜索并尝试了以下方法,但似乎没有任何效果:
AsyncCallback aCallback = new AsyncCallback(AcceptCallback);
AsyncCallback aCallback = new AsyncCallback(sListener.AcceptCallback);
AsyncCallback aCallback = new AsyncCallback(this.AcceptCallback);
AsyncCallback aCallback = new AsyncCallback(this.IAsyncResult);
AsyncCallback aCallback = new AsyncCallback(aCallback);
AsyncCallback aCallback = new AsyncCallback(sListener.aCallback);
AsyncCallback aCallback = new AsyncCallback(this.aCallback);
我正在查看的另一个参考是https://stackoverflow.com/questions/3722270/c-sharp-server-does-not-trigger-acceptcallback
这是我第一次在 C# 中做套接字。