This commit is contained in:
sc committed 2024-06-29 21:56:26 +08:00
commit 86ae16fa94
2 files changed
+55 -57

No files matched your search

+44 -49
View File
@@ -24,8 +24,9 @@ namespace formula_manage.UserClass
//字典集合:存储IP和Socket的集合
public static Dictionary<string, Socket> OnLineList = new Dictionary<string, Socket>();
//当前时间
DataTable IPdataTable = new DataTable(); //建立缓存
//当前时间
private string CurrentTime
{
get { return DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine; }
@@ -84,46 +85,47 @@ namespace formula_manage.UserClass
{
while (true)
{
//定义一个2M的缓冲区
byte[] buffer = new byte[1024 * 1024 * 2];
int length = -1;
try
{
length = clientSocket.Receive(buffer);
}
catch (Exception)
{
//定义一个2M的缓冲区
byte[] buffer = new byte[1024 * 1024 * 2];
int length = -1;
try
{
length = clientSocket.Receive(buffer);
}
catch (Exception)
{
//客户端下线了
//更新在线列表
string ip = clientSocket.RemoteEndPoint.ToString();
UserClass.LogGing.LogGingDATA("IP_Line = " + ip);
string ip = clientSocket.RemoteEndPoint.ToString();
UserClass.LogGing.LogGingDATA("IP_Line = " + ip);
// AddOnLine(ip, false);
OnLineList.Remove(ip);
break;
}
break;
}
if (length == 0)
{
if (length == 0)
{
//客户端下线了
//更新在线列表
string ip = clientSocket.RemoteEndPoint.ToString();
UserClass.LogGing.LogGingDATA("IP_Line = " + ip);
//更新在线列表
string ip = clientSocket.RemoteEndPoint.ToString();
UserClass.LogGing.LogGingDATA("IP_Line = " + ip);
// AddOnLine(ip, false);
OnLineList.Remove(ip);
break;
}
break;
}
if (length > 0)
{
infoR = econding.GetString(buffer, 0, length);
//ShowMessage(info);
string ip = clientSocket.RemoteEndPoint.ToString();
Bn_Send(ip, infoR+"return");
}
}
@@ -169,34 +171,27 @@ namespace formula_manage.UserClass
/// <summary>
/// 消息发送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void Bn_Send(string IP ,string DAT)
{
if (OnLineList.ContainsKey(IP))
{
OnLineList[IP].Send(econding.GetBytes(DAT));
}
if (OnLineList.ContainsKey(IP))
{
OnLineList[IP].Send(econding.GetBytes(DAT));
}
}
/*
/// <summary>
/// 群发功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_SendAll_Click(object sender, EventArgs e)
/// <summary>
/// 群发功能
/// </summary>
public static void Btn_SendAll(string DAT)
{
foreach (string item in OnLineList.Keys.ToArray())
{
foreach (string item in this.lst_Online.Items)
if (OnLineList.ContainsKey(item))
{
if (OnLineList.ContainsKey(item))
{
OnLineList[item].Send(econding.GetBytes(this.txt_Send.Text.Trim()));
}
OnLineList[item].Send(econding.GetBytes(DAT));
}
}*/
}
}
}
}