Beispiel #1
0
        private Hashtable GetXMLFromStream(NetworkStream stream)
        {
            StringBuilder build = new StringBuilder();

            byte[] message = new byte[1024];
            while (true)
            {
                int x = stream.Read(message, 0, 1024);
                if (x == 0)
                {
                    break;
                }
                build.Append(Encoding.UTF8.GetString(message, 0, x));
            }
            DesXML      desxml = new DesXML();
            XmlDocument doc    = desxml.StringToXML(build.ToString());

            return(desxml.XmlToHashTable(doc));
        }
Beispiel #2
0
 public void DealXml(XmlDocument doc)
 {
     try
     {
         DesXML des     = new DesXML();
         String local   = des.GetValueById(doc, "local");
         String oldnext = des.GetValueById(doc, "next");
         String next    = ConfigurationSettings.AppSettings["serverip"];
         doc = des.SetValueById(doc, "before", local);
         doc = des.SetValueById(doc, "local", oldnext);
         doc = des.SetValueById(doc, "next", next);
         String  message = des.XMLToString(doc);
         String  port    = ConfigurationSettings.AppSettings["fromback"];
         Network net     = new Network();
         net.Deal(message, port);
     }
     catch (Exception ex)
     {
         throw new Exception("Deal XML Error." + ex.Message);
     }
 }
Beispiel #3
0
        public void ListenDeal()
        {
            string port = ConfigurationSettings.AppSettings["listenclient"];

            try
            {
                TcpListener listener = new TcpListener(Convert.ToInt32(port));
                listener.Start();
                while (true)
                {
                    byte[]        result = new byte[2050];
                    StringBuilder build  = new StringBuilder();
                    TcpClient     client = listener.AcceptTcpClient();
                    NetworkStream stream = client.GetStream();
                    while (true)
                    {
                        int x = stream.Read(result, 0, 2050);
                        if (x == 0)
                        {
                            break;
                        }
                        build.Append(Encoding.UTF8.GetString(result, 0, x));
                    }
                    client.Close();
                    //TODO:First AES decrypt, Then I have no deal the message, but it should be deal
                    DesXML      desxml = new DesXML();
                    XmlDocument doc    = desxml.StringToXML(build.ToString());
                    MessageBox.Show("处理成功");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Deal listen Error.");
            }
            return;
        }