473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 4756
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Stingray | last post by:
Are there any know problems with using a MemoryStream as a backing store for a CryptoStream? I'm trying to simply encrypt and decrypt text in memory. I'd like to create some simple methods to...
0
by: Stelrad Doulton | last post by:
Hi all, I am writting a Jabber-esque client-server application and have run into an issue with the XmlTextReader constructor when passing a NetworkStream - It hangs forever, apparently this is...
8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt solution. It runs as a service, watches for files with...
5
by: weixiang | last post by:
Hi, I want to use DES and CryptoStream to serialize a encrypted stream to a file with a header "CRYPT". And I wrote these code: To store: FileStream fileStream = new FileStream(fileName,...
1
by: Borgbjerg | last post by:
I've got a multi-threaded server (we are very early in the project, trying to uncover some risks), and I want to send data using XML. The class ServerAdapter is supposed to connect to the server...
3
by: James | last post by:
Hi, I am developing a ActiveX Control which will be used in a web page. The control will encrypt some value then decrypt it when the web page opens next time. I tested the control in a windows...
2
by: pesso | last post by:
I have the following code that's taken and modified from a got_dot_net example. I'm trying to decrypt an Xml file that's been encrypted. I can dump the decrypted stream to the console, but if I...
1
by: Nicholas Holder | last post by:
A client creates a connection to the server using the TCPListener/Client classes and transfers data via a NetworkStream. When the client connects, the server creates a process and redirects its...
3
by: g66g08d14 | last post by:
Hi. We have a Jabber-esque client server package that uses XMPP for communication over network sockets. Using .NET 2.0, I need to read a full stanza (i.e. balanced xml) as soon as available...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.