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

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

// Create a TCP/IP socket. 
Socket client = new Socket(AddressFamily.InterNetwork, 
SocketType.Stream, ProtocolType.Tcp); 
// Connect to the remote endpoint. 
client.BeginConnect( remoteEP, 
new AsyncCallback(ConnectCallback), client); 
connectDone.WaitOne(); 
// Send test data to the remote device. 
Send(client,"This is a test<EOF>"); 
sendDone.WaitOne(); 
// Receive the response from the remote device. 
Receive(client); 
receiveDone.WaitOne(); 
// Write the response to the console.