我有一个任务是创建一个简单的winsock聊天程序,它使用VB.6作为客户端,C#作为服务器。 当它与一个客户端一起使用时效果很好。但我无法处理多个客户端。有人可以帮帮我吗?我在谷歌搜索但我几乎找不到答案。 THX
这是我的代码
当连接请求到来时:
private void sckMain_ConnectionRequest(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent e)
{
sckMain.Close();
sckMain.Accept(e.requestID);
IsConnect = true;
//lstSocket = new List<clsSocket>();
//runTCP();
//sckMain.Close();
//with this commands we accept the connection request to the server..
//now we are connected with the client
txtHistory.Text += "Client Connected :" + sckMain.RemoteHostIP + Environment.NewLine;
}
接收数据时
private void sckMain_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
{ //ON DATA ARRIVAL
string data = "";
object objData = (object)data;
sckMain.GetData(ref objData);
data = objData.ToString();
txtHistory.Text += "[" + sckMain.RemoteHostIP + "]: " + data + Environment.NewLine;
}