Beispiel #1
0
 /// <summary>
 /// 向指定用户发送消息
 /// </summary>
 /// <param name="msg">要发送的消息内容</param>
 /// <param name="ToWho">要发送消息的目标用户</param>
 /// <returns>返回发送结果是成功还是失败</returns>
 private void MessageSend()
 {
     try
     {
         string      TOIpNumber = "";
         CheckOutNum NAN        = new CheckOutNum(ToWho);
         this.ToIpName = NAN.QQname;
         this.MSG      = msg;
         TOIpNumber    = NAN.QQnumber;
         XmlDataDocument Xml = new XmlDataDocument();
         Xml.Load("online.dat");
         XmlNode root = Xml.SelectSingleNode("root");
         for (int i = 0; i < root.ChildNodes.Count; i++)
         {
             if (root.ChildNodes[i].ChildNodes[0].InnerText.Trim() == TOIpNumber.Trim())
             {
                 this.IpEndPoint = root.ChildNodes[i].ChildNodes[1].InnerText.Trim();
                 break;
             }
         }
         CheckOutIpPoint IEP  = new CheckOutIpPoint(IpEndPoint);
         TcpClient       Send = new TcpClient();
         Send.Connect(IEP.IpAdd, 5281);
         Stream       stm  = Send.GetStream();
         UTF8Encoding asen = new UTF8Encoding();
         byte[]       ba   = asen.GetBytes("2;" + ShareDate.ThisUser.Trim() + ";" + MSG);  //参数格式为(标识;原用户;消息内容)
         stm.Write(ba, 0, ba.Length);
         Send.Close();
         result = true;
     }
     catch
     {
         result = false;
     }
 }
Beispiel #2
0
 private static void TellIng()
 {
     try
     {
         string          onlineInf = "online.dat";
         XmlDataDocument Xml       = new XmlDataDocument();
         Xml.Load(onlineInf);
         XmlNode root = Xml.SelectSingleNode("root");
         for (int i = 0; i < root.ChildNodes.Count; i++)
         {
             if (root.ChildNodes[i].ChildNodes[0].InnerText.Trim() != UidTemp.Trim())
             {
                 TcpClient       tcpclnt    = new TcpClient();
                 string          IpEndPoint = root.ChildNodes[i].ChildNodes[1].InnerText;
                 CheckOutIpPoint check      = new CheckOutIpPoint(IpEndPoint);
                 tcpclnt.Connect(check.IpAdd, 5281);
                 Stream       stm  = tcpclnt.GetStream();
                 UTF8Encoding asen = new UTF8Encoding();
                 byte[]       ba   = asen.GetBytes("1;" + UidTemp);
                 stm.Write(ba, 0, ba.Length);
                 tcpclnt.Close();
             }
         }
     }
     catch
     {}
 }