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

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

Send(handler, content); 
} else { 
// Not all data received. Get more. 
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, 
new AsyncCallback(ReadCallback), state); 



private static void Send(Socket handler, String data) { 
// Convert the string data to byte data using ASCII encoding. 
byte[] byteData = Encoding.ASCII.GetBytes(data); 
// Begin sending the data to the remote device. 
handler.BeginSend(byteData, 0, byteData.Length, 0, 
new AsyncCallback(SendCallback), handler);