c#(Socket)异步套接字代码示例

2019-12-26 11:15:51于海丽

// Wait until a connection is made before continuing. 
allDone.WaitOne(); 

} catch (Exception e) { 
Console.WriteLine(e.ToString()); 

Console.WriteLine("nPress ENTER to continue..."); 
Console.Read(); 

public static void AcceptCallback(IAsyncResult ar) { 
// Signal the main thread to continue. 
allDone.Set(); 
// Get the socket that handles the client request. 
Socket listener = (Socket) ar.AsyncState; 
Socket handler = listener.EndAccept(ar);