//将新连接的用户加到HashTable列表中
list.Add(userName, MySocket);
string svrlog = string.Format("[系统消息]新用户 {0} 在 {1} 已连接... 当前在线人数: {2}", userName, DateTime.Now, list.Count);
richTextBox1.AppendText(svrlog);
myThread = new Thread(new ParameterizedThreadStart(ThreadFunc));
myThread.Start(userName);
//向所有用户发送消息
foreach (DictionaryEntry de in list)
{
string clientName = de.Key as string;
Socket clientSkt = de.Value as Socket;
if (!clientName.Equals(userName))
{
clientSkt.Send(Encoding.Unicode.GetBytes(svrlog));
}
}
这个可以向所有在线用户发送信息,如何向自己选定的用户发送信息,checkedlistbox选定用户,
list.Add(userName, MySocket);
string svrlog = string.Format("[系统消息]新用户 {0} 在 {1} 已连接... 当前在线人数: {2}", userName, DateTime.Now, list.Count);
richTextBox1.AppendText(svrlog);
myThread = new Thread(new ParameterizedThreadStart(ThreadFunc));
myThread.Start(userName);
//向所有用户发送消息
foreach (DictionaryEntry de in list)
{
string clientName = de.Key as string;
Socket clientSkt = de.Value as Socket;
if (!clientName.Equals(userName))
{
clientSkt.Send(Encoding.Unicode.GetBytes(svrlog));
}
}
这个可以向所有在线用户发送信息,如何向自己选定的用户发送信息,checkedlistbox选定用户,
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货