void SendMsgToClient(string msg, int clientNumber)
{
// Convert the reply to byte array
byte[] byData = System.Text.Encoding.ASCII.GetBytes(msg);
Socket workerSocket = (Socket)m_workerSocketList[clientNumber - 1];
//workerSocket.Send(byData);
workerSocket.BeginSend(byData, 0, byData.Length, 0,
new AsyncCallback(SendCallback), workerSocket);
}
private void SendCallback(IAsyncResult asyn)
{
Socket client = (Socket)asyn.AsyncState;
// 完成数据发送.
int bytesSent = client.EndSend(asyn);
}
完整的代码下载