473,511 Members | 15,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read XML from a scoket

Hi,
I have a socket connection where messages are formatted as XML, i.e. each
message is in the form <msg>..</msg>.
Is there an easy way to get a XMLDocument for each message form the socket
stream?
I tried with XMLTextReader and the NetworkStream of the socket but the
reader blocks until the socket is closed.
Any help?
regards
Nov 12 '05 #1
4 4221
Lets see some code. It sounds like you're on the right path but you
might need to add a "flush()" call in order to avoid buffering in your
stream but gimme your code, me wants it.

Rgd,
Peter Theill

Nov 12 '05 #2
here it is
sock.Connect(addr);
NetworkStream strm = new NetworkStream(sock,false);
XmlTextReader rdr = new XmlTextReader(strm);
rdr.Read(); // the program blocks here until the sock is closed

or

sock.Connect(addr);
NetworkStream strm = new NetworkStream(sock,false);
XmlDocument xdoc = new XMLDocument();
xdoc.Load(strm); // it blocks here

The server is working ok and sends the xml messages to the client.


"Peter Theill" <th****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Lets see some code. It sounds like you're on the right path but you
might need to add a "flush()" call in order to avoid buffering in your
stream but gimme your code, me wants it.

Rgd,
Peter Theill

Nov 12 '05 #3
If you are using an 1.1 Sp1, there is a bug in the code. If you are using
1.1 RTM, it should be fine. Instead of directly passing the Networkstream to
the xmltextreader, can you consume it completely and hold it in memory as a
workaround? And then send that to the xmltextreader?

"Drago Velchev" <dv******@refco.fr> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
here it is
sock.Connect(addr);
NetworkStream strm = new NetworkStream(sock,false);
XmlTextReader rdr = new XmlTextReader(strm);
rdr.Read(); // the program blocks here until the sock is closed

or

sock.Connect(addr);
NetworkStream strm = new NetworkStream(sock,false);
XmlDocument xdoc = new XMLDocument();
xdoc.Load(strm); // it blocks here

The server is working ok and sends the xml messages to the client.


"Peter Theill" <th****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Lets see some code. It sounds like you're on the right path but you
might need to add a "flush()" call in order to avoid buffering in your
stream but gimme your code, me wants it.

Rgd,
Peter Theill


Nov 12 '05 #4
There is a bug with .NET SP 1.1 using XmlTextReader with networkStream.

It works for me:

MemoryStream ms = new MemoryStream();

StreamReader sr = new StreamReader(ns);

if (ns.DataAvailable)
{
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);

XmlTextReader reader = new XmlTextReader(ms);
if (reader.Read())
{
objXmlDocument.Load(reader);
}
}

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8970
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
11
12660
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
12
11631
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
2
3069
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing...
4
3834
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would appreciate some guidance. I am trying to 'time out' a...
6
2651
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate...
8
23886
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
1
3979
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
0
4696
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
0
7251
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
7148
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
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7089
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
5673
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,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.