473,666 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with an XmlTextReader with a NetworkStream

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 (which
works fine), to send data, but on the same stream be able to read
data (which is causing problems).

In the function "bool Connect()", we want to instantiate the
XmlTextReader with the stream that we got from the 'TcpClient
client', but somehow that goes wrong. No exception is cast, but the
problem definately has something to do with the stream that we get
from the call 'client.GetStre am()'.
When we try to do the exact same thing, with a stream NOT from a
TcpClient, there is no problem. We've checked to see if it had
something to do with the access-property on the connection (the
'Socket') on the serverside, but it came up negative. I am pretty
much out of ideas, so if you can help me out, it'd be great (first
time here, so I dont know the standarts) :)

We've checked how far it gets with text-outputs, so we KNOW that the
XmlTextReader causes the problem.

Here is the part of code that fails.

public class ServerAdapter : IServerAdapter
{
private IServerEventHan dler serverEventHand ler;

private TcpClient client;
private NetworkStream stream;

private Thread readThread;

private XmlTextReader streamReader;
private XmlTextWriter streamWriter;
private BinaryReader reader;

private XmlValidatingRe ader validatingReade r;
private XmlSchemaCollec tion schemaCollectio n;

public ServerAdapter()
{

}

public ServerAdapter( IServerEventHan dler serverEventHand ler ):base()
{
this.serverEven tHandler = serverEventHand ler;

}

public bool Connect()
{
bool connected = false;

try
{
client = new TcpClient();
client.Connect( "10.0.55.12 ", 4312 );

stream = client.GetStrea m();

streamReader = new XmlTextReader( stream );

streamWriter = new XmlTextWriter( stream, new
System.Text.UTF 8Encoding() );

blablabla....

Thanks in advance

...Borgbjerg
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #1
1 2513
Borgbjerg <dm******@mail. ikasths-dot-dk.no-spam.invalid> wrote:
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 (which
works fine), to send data, but on the same stream be able to read
data (which is causing problems).

In the function "bool Connect()", we want to instantiate the
XmlTextReader with the stream that we got from the 'TcpClient
client', but somehow that goes wrong. No exception is cast, but the
problem definately has something to do with the stream that we get
from the call 'client.GetStre am()'.
When we try to do the exact same thing, with a stream NOT from a
TcpClient, there is no problem. We've checked to see if it had
something to do with the access-property on the connection (the
'Socket') on the serverside, but it came up negative. I am pretty
much out of ideas, so if you can help me out, it'd be great (first
time here, so I dont know the standarts) :)


I've seen this before, and I believe it's a bug in XmlTextReader which
assumes it will have a large "chunk" of data to read to start with.

Have a look at

http://groups.google.com/groups?thre...07dfd57989867%
40msnews.micros oft.com

(aka http://tinyurl.com/347dh)

for more details.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

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

Similar topics

2
1887
by: Ayende Rahien | last post by:
I've a problem in my code using NetworkStream. I've a server which listen to a port, and then Read() from it, and a client that send data. My NetworkStream is wrapped in a CryptoStream, and my problem is that I don't get all the data that I send. When I use NetworkStream, all is working properly, but when I use CryptoStream (initialize to use the NetworkStream), I only get partial data. Anyone knows why this is happenning? I would...
1
556
by: cmjman | last post by:
I have an issue where networkStream.Write doesn't perform its write downstream from my client program until the network stream is closed. I then see the data that was sent appear on the other side. I am sending a small amound of data and read where data wasn't sent until the buffer reached a larger size. However, there is a TcpClient property call NoDelay that is suppose to eliminate this delay. Here is a snippet of my code below. Can...
2
7936
by: Theo | last post by:
Hi, I am using a tcpclient and a tcplistener to send and receive packets. The client sends a packet and the listener replies with another one. I can send 2 packets and get an answer from the listener but it fails to send a third packet. I don't get any error messages. The client sends the packet successfully but it never arrives to the listener. This only happens when I send the packets one straight after the other. If I place a delay of 2...
2
3478
by: David Dvali | last post by:
Hello. I wnat to read some data from server, I'm using following code: ---------------------------------------------------------------------------------------- TcpClient cl = new TcpClient(); cl.Connect("SomeHost", 9000); NetworkStream networkStream = cl.GetStream(); if (!networkStream.CanRead) return;
12
2033
by: Brian Henry | last post by:
I wrote a simple client / server app (nothing major, just sends text) it works fine locally on the same system, but once i move the client to a remote system it errors and gives me "No connection could be made because the target machine actively refused it" what exactly does that mean? the targed machine actively refused it? i have port forwarding set up correctly on ISA server to forward it to the server maching...
0
2164
by: Harley | last post by:
Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and can't see that I am doing anything wrong (i obviousely am though) everything "works", client connects to server and when anything is sent to the server it starts the mp3 and passes all messages the way i ment for it to except that my server is...
0
1527
by: Tim Wagaman | last post by:
I an having issuses with a loop I am running to keep checking for messages coming across our line. The goal: Listen for messages on port 5001 and print the messages into a text file. The port must stay open at all times and only close if no activity for 60 seconds. The problem: If I do a read on a networkstream and the connection is closed
4
1273
by: Tom Shelton | last post by:
Problem: XmlTextReader Constructor hangs until underlying socket closes when passed a NetworkStream. Example: Dim reader As New XmlTextReader (New NetworkStream(s, False)) I can positively confirm by the way that this only happens AFTER installation of SP1 for framework 1.1. So, has anyone else have this
7
4266
by: littleIO | last post by:
Hi, I'm stuck on a very simple problem and just cant seem to get around it, little help would be much appreciated. I have a server which listens, receives calls, processes them and sends back the results to clients. The code below makes the client application not to respond. Client can send data but is stuck in the process of waiting information back from the server. Any ideas?
0
8448
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.