C#中Socket服务端代码分享(5)

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);  
        }

完整的代码下载

免费下载地址在

用户名与密码都是

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wydspp.html