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

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

new ManualResetEvent(false); 
private static ManualResetEvent receiveDone = 
new ManualResetEvent(false); 
// The response from the remote device. 
private static String response = String.Empty; 
private static void StartClient() { 
// Connect to a remote device. 
try { 
// Establish the remote endpoint for the socket. 
// The name of the  
// remote device is "host.contoso.com". 
IPHostEntry ipHostInfo = Dns.Resolve("host.contoso.com"); 
IPAddress ipAddress = ipHostInfo.AddressList[0]; 
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);