Note that there are some explanatory texts on larger screens.

plurals
  1. POc# XmlReader with base64 innertext
    text
    copied!<p>Ok here is my problem. I am trying to take a screenshot, add it to an xmldocument, send it over a socket, and read it with a XmlReader.</p> <p>Here's some code...</p> <p>Server Side</p> <pre><code>private void SendRandomData(object data) { XMLShitSock sock = data as XMLShitSock; if(sock != null) { int incnum = 0; while(sock.Connected) { XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlNode productsNode = doc.CreateElement("image"); productsNode.InnerText = Convert.ToBase64String(Program.CaptureImageToBytes(new Point(0, 0), new Rectangle(0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height), ImageFormat.Png)); doc.AppendChild(productsNode); string s = XMLShitSock.GetXmlString(doc); doc.Save("temp.xml"); sock.WriteXMLMessage(doc); incnum++; Thread.Sleep(5000); } } } </code></pre> <p>sock.WriteXMLMessage</p> <pre><code>public bool WriteXMLMessage(XmlDocument doc) { try { ShittySocket.Client.Send(Encoding.ASCII.GetBytes(GetXmlString(doc))); return true; } catch(SocketException se) { this.Close(); return false; } } </code></pre> <p>To Read input</p> <pre><code>private void doInput() { MemoryStream ms = new MemoryStream(); NetworkStream ns = new NetworkStream(ShittySocket.Client, false); while(_connected) { if(ns.DataAvailable) { StreamReader sr = new StreamReader(ns); char[] b = new char[512]; int nread = sr.Read(b, 0, 512); ms.Write(System.Text.Encoding.ASCII.GetBytes(b, 0, nread), 0, nread); ms.Seek(0, System.IO.SeekOrigin.Begin); XmlReaderSettings xrs = new XmlReaderSettings(); XmlReader reader = XmlReader.Create(ms); if(reader.Read()) { XmlDocument objXmlDocument = new XmlDocument(); objXmlDocument.Load(reader); onInput(this, objXmlDocument); ms.Close(); ms = new MemoryStream(); } } Thread.Sleep(100); } } </code></pre> <p>Problem I'm having is I get an error in doInput() saying the end of the document was reached without find the tag. I saved the xml file and looked through it and it exists, and I didn't even find any &lt; characters besides those in the actual tags, so I'm not sure what's going on here. I'm obviously missing something. </p> <p>Also, if you have concerns with the semantics or coding style, or anything that doesn't actually answer the question, please leave it as a comment, since it's not an answer. </p> <p>Also I've look through this ->> <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.readbase64.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.readbase64.aspx</a> and I'm hoping that there is a better way to deal with base64 data than separating it from the XMLDocument itself. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload