public void appServer_NewSessionConnected(DTSession session) { var host = session.LocalEndPoint; ipAddress_Connect = session.RemoteEndPoint.ToString(); sessionList.Add(ipAddress_Connect, session); }
public static void sendSth(DTSession session, string thing) { byte[] rsp = Encoding.UTF8.GetBytes(thing); byte[] re = new byte[] { Convert.ToByte(rsp.Length) }; byte[] result = new byte[rsp.Length + 4]; re.CopyTo(result, 3); rsp.CopyTo(result, 4); session.Send(result, 0, result.Length); }
public void appServer_SessionClosed(DTSession session, CloseReason value) { try { ipAddress_Close = session.RemoteEndPoint.ToString(); sessionList.Remove(ipAddress_Close); if (AddressList.Keys.Contains(ipAddress_Close)) { string na = AddressList[ipAddress_Close]; string[] sp = na.Split('-'); rList.Remove(sp[1]); RemoveCheckBox(AddressList[ipAddress_Close]); AddressList.Remove(ipAddress_Close); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public void appServer_NewRequestReceived(DTSession session, DTRequestInfo requestInfo) { //requestInfo.cmd 接收的数据头 //requestInfo.Body 接收的内容 try { int cmd = requestInfo.cmd; string node = requestInfo.node; ipAddress_Receive = session.RemoteEndPoint.ToString(); if (cmd == 84) { if (isNum(node.Substring(0, 1)) && isNum(node.Last().ToString())) { if (AddressList.Values.Contains(node)) { string resultNew = "{\"cmd\":86}"; sendSth(sessionList[ipAddress_Receive], resultNew); return; } AddressList.Add(ipAddress_Receive, node); string[] s = node.Split('-');//用-进行分割 l = s[0]; rList.Add(s[1]); int Num = Convert.ToInt32(s[0]) * 100 + Convert.ToInt32(s[1]);//转换 ipList.Add(Num, ipAddress_Receive); AddCheckBoxLeft(node); string result = "{\"cmd\":85}"; sendSth(sessionList[ipAddress_Receive], result); } } else if (cmd == 127) { string result = "{\"cmd\":128}"; sendSth(sessionList[ipAddress_Receive], result); } else if (cmd == 67) { if (AddressList.Keys.Contains(ipAddress_Close)) { RemoveCheckBox(AddressList[ipAddress_Close]); AddressList.Remove(ipAddress_Close); } } else if (cmd == 87) { if (isNum(node.Substring(0, 1)) && isNum(node.Last().ToString())) { RemoveCheckBox(AddressList[ipAddress_Receive]); if (AddressList.Values.Contains(node)) { string resultNew = "{\"cmd\":86}"; sendSth(sessionList[ipAddress_Receive], resultNew); return; } string[] s = node.Split('-'); //用-进行分割 int Num = Convert.ToInt32(s[0]) * 100 + Convert.ToInt32(s[1]); //转换 ipList.Add(Num, ipAddress_Receive); AddCheckBoxLeft(node); AddressList[ipAddress_Receive] = node; string result = "{\"cmd\":85}"; sendSth(sessionList[ipAddress_Receive], result); } } } catch (Exception E) { MessageBox.Show(E.Message); } }