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

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


private static void SendCallback(IAsyncResult ar) { 
try { 
// Retrieve the socket from the state object. 
Socket handler = (Socket) ar.AsyncState; 
// Complete sending the data to the remote device. 
int bytesSent = handler.EndSend(ar); 
Console.WriteLine("Sent {0} bytes to client.", bytesSent); 
handler.Shutdown(SocketShutdown.Both); 
handler.Close(); 
} catch (Exception e) { 
Console.WriteLine(e.ToString()); 


public static int Main(String[] args) {