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

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

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


private static void ReceiveCallback( IAsyncResult ar ) { 
try { 
// Retrieve the state object and the client socket  
// from the asynchronous state object. 
StateObject state = (StateObject) ar.AsyncState; 
Socket client = state.workSocket; 
// Read data from the remote device. 
int bytesRead = client.EndReceive(ar); 
if (bytesRead > 0) { 
// There might be more data, so store the data received so far.