471,078 Members | 812 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,078 software developers and data experts.

NetworkStream/CryptoStream/XMLTextReader Problems in VB.net

Hi :)

I'm having some major trouble with an XML Client/Server application that I
am writing. I am using NetworkStream with CryptoStream to Read and Write
XML between computers. Now, whenever I write the XML, the Server section
which uses the XMLTextReader Class will not accept EndElements period, and
neither the ReadStartElement or ReadEndElement will work properly. However,
if I only send to WriteStartElements over the network, the Server will
receive it fine if I only use the Read Method. It will not accept
EndElements period. Since this application is just a test application, I'm
running it all on the same computer multi-threaded. If this is the problem,
please tell me so. I don't think it is, however, becuase if I just send
XMLStartElements, it reads those just fine with the XML.Read method no
matter how many start elements I send. I'm sure there's a very easy fix to
this, but, just in case, I have attached some of the more pertinent code
segments for your review. I didn't include the Listener section and the
Connect section because both of those work fine. Any help that anybody could
provide would be greatly appreciated. Thank you for your time.

Server App::

Button3.Text = "Waiting..."

Button3.ForeColor = Color.DarkRed

Dim ConnectedStream As Net.Sockets.NetworkStream

ConnectedStream = Server_Client.GetStream

Dim XMLDoc As New Xml.XmlDocument()

Dim CryptoReadStream As New Security.Cryptography.CryptoStream _

(ConnectedStream, _

EncProvider.CreateDecryptor(EncProvider.Key, EncProvider.IV), _

Security.Cryptography.CryptoStreamMode.Read)

Dim XMLRead As New Xml.XmlTextReader(CryptoReadStream)

XMLRead.WhitespaceHandling = Xml.WhitespaceHandling.None

Do While 1

XMLRead.Read()

Loop

Client App::

Dim ConnectedStream As Net.Sockets.NetworkStream

ConnectedStream = Client_Client.GetStream

Dim CryptoWriteStream As New Security.Cryptography.CryptoStream _

(ConnectedStream, _

EncProvider.CreateEncryptor(EncProvider.Key, EncProvider.IV), _

Security.Cryptography.CryptoStreamMode.Write)

Dim XMLWrite As New Xml.XmlTextWriter(CryptoWriteStream,
System.Text.Encoding.Default)

Button4.Text = "Sending..."

Button4.ForeColor = Color.DarkRed

XMLWrite.WriteStartElement("Start1")

XMLWrite.WriteEndElement()

XMLWrite.WriteStartElement("Start2")

XMLWrite.WriteEndElement()

XMLWrite.Flush()

XMLWrite.Close()

Button4.Text = "Message Sent!"

Button4.ForeColor = Color.DarkGreen
Thank you so much!!!
If you can help me out at all, I would surely appreciate it.

-- Casey J. Watson


Nov 11 '05 #1
1 4645
Not sure that this is exactly the problem, and the only problem.
In you example you are sending not well-formed document but document
fragment:
<Start1><Start1/>
<Start2><Start2/>

To change this you can wrap your fragment into additional element:
XMLWrite.WriteStartElement("root")
XMLWrite.WriteStartElement("Start1")
XMLWrite.WriteEndElement()
XMLWrite.WriteStartElement("Start2")
XMLWrite.WriteEndElement()
XMLWrite.WriteEndElement()

Sergey

"Casey Watson" <dy*****@collegeclub.com> wrote in message
news:#6**************@TK2MSFTNGP12.phx.gbl...
Hi :)

I'm having some major trouble with an XML Client/Server application that I
am writing. I am using NetworkStream with CryptoStream to Read and Write
XML between computers. Now, whenever I write the XML, the Server section
which uses the XMLTextReader Class will not accept EndElements period, and
neither the ReadStartElement or ReadEndElement will work properly. However, if I only send to WriteStartElements over the network, the Server will
receive it fine if I only use the Read Method. It will not accept
EndElements period. Since this application is just a test application, I'm running it all on the same computer multi-threaded. If this is the problem, please tell me so. I don't think it is, however, becuase if I just send
XMLStartElements, it reads those just fine with the XML.Read method no
matter how many start elements I send. I'm sure there's a very easy fix to this, but, just in case, I have attached some of the more pertinent code
segments for your review. I didn't include the Listener section and the
Connect section because both of those work fine. Any help that anybody could provide would be greatly appreciated. Thank you for your time.

Server App::

Button3.Text = "Waiting..."

Button3.ForeColor = Color.DarkRed

Dim ConnectedStream As Net.Sockets.NetworkStream

ConnectedStream = Server_Client.GetStream

Dim XMLDoc As New Xml.XmlDocument()

Dim CryptoReadStream As New Security.Cryptography.CryptoStream _

(ConnectedStream, _

EncProvider.CreateDecryptor(EncProvider.Key, EncProvider.IV), _

Security.Cryptography.CryptoStreamMode.Read)

Dim XMLRead As New Xml.XmlTextReader(CryptoReadStream)

XMLRead.WhitespaceHandling = Xml.WhitespaceHandling.None

Do While 1

XMLRead.Read()

Loop

Client App::

Dim ConnectedStream As Net.Sockets.NetworkStream

ConnectedStream = Client_Client.GetStream

Dim CryptoWriteStream As New Security.Cryptography.CryptoStream _

(ConnectedStream, _

EncProvider.CreateEncryptor(EncProvider.Key, EncProvider.IV), _

Security.Cryptography.CryptoStreamMode.Write)

Dim XMLWrite As New Xml.XmlTextWriter(CryptoWriteStream,
System.Text.Encoding.Default)

Button4.Text = "Sending..."

Button4.ForeColor = Color.DarkRed

XMLWrite.WriteStartElement("Start1")

XMLWrite.WriteEndElement()

XMLWrite.WriteStartElement("Start2")

XMLWrite.WriteEndElement()

XMLWrite.Flush()

XMLWrite.Close()

Button4.Text = "Message Sent!"

Button4.ForeColor = Color.DarkGreen
Thank you so much!!!
If you can help me out at all, I would surely appreciate it.

-- Casey J. Watson

Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Stingray | last post: by
reply views Thread by Stelrad Doulton | last post: by
5 posts views Thread by weixiang | last post: by
2 posts views Thread by pesso | last post: by
1 post views Thread by Nicholas Holder | last post: by
3 posts views Thread by g66g08d14 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.