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

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

client.RemoteEndPoint.ToString()); 
// Signal that the connection has been made. 
connectDone.Set(); 
} catch (Exception e) { 
Console.WriteLine(e.ToString()); 


private static void Receive(Socket client) { 
try { 
// Create the state object. 
StateObject state = new StateObject(); 
state.workSocket = client; 
// Begin receiving the data from the remote device. 
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, 
new AsyncCallback(ReceiveCallback), state);