在 Stefen Toub 的代码Awaiting Socket Operations中:它没有提到其异步方法的使用。我的意思是服务器程序将如何使用await调用异步方法?也没有任何main () 。请详细说明这一点。我尝试创建一个 main() 并调用SocketExtensions.ReceiveAsync(sock,awaitable);
public static void Main(string[] str)
{
Console.WriteLine("\n\n<<<<<<<<<<< Server is starting... >>>>>>>>>>>>>>>>>");
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10100);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var args = new SocketAsyncEventArgs();
args.SetBuffer(new byte[0x100000], 0, 0x100000);
var awaitable = new SocketAwaitable(args);
while(true)
SocketExtensions.ReceiveAsync(sock,awaitable);
}
但这对我不起作用。