472,354 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

NetworkStream & inconsistent protocols

Hi,
I have been working with what i believe is, an poorly designed
client/protocol, and this is causing me no end of headaches determining the
end of a 'fragment'. The header of each fragment ends in a constant fasion
(single line consisting of a carriage return) however the payload afterwards
containing xml fragment does not end in a consistent fasion, this would be
fine if the stream was closed and the protocol was '1 shot' and you could
detect this but this isn't the case with all the fragments(consistency is
nowhere to be found in this system!) and often the client expects a return
fragment back down the same stream (in the same transaction).
The protocol is very http in style.

the transaction is (in one stream):
(client) (server) (client)
(server)
header header header
header
/r/n --> /r/n -->
--> /r/n
xml fragment xmlfragment xmlfragment
xmlfragment

It is detection of the end of the xmlfragment which holds no consistency and
the client holds the connection open awaiting the return fragment but the
server sits on the readLine waiting for a response from the client. Only
when the client closes the connection because it doesn't return a fragment
will the code continue (with an exception) but by then the transaction is
then spoilt as the client has closed off.

The other read methods on in the StreamReader class exhibit the same
behaviour. I am reluctant to use intrenal timers or other workarounds, and
the problem does not lie with the classes and methods but in the protocol.

Has anyone come accross a similar situation with other 'protocols' and
found/not found any workarounds?

I can supply some samples/code if people think they will help but at this
stage don't feel they wil add anything.

thanks in advance for your help.

Mike




Nov 15 '05 #1
2 1506
mike b <te**@mike.here> wrote:
I have been working with what i believe is, an poorly designed
client/protocol, and this is causing me no end of headaches determining the
end of a 'fragment'. The header of each fragment ends in a constant fasion
(single line consisting of a carriage return) however the payload afterwards
containing xml fragment does not end in a consistent fasion, this would be
fine if the stream was closed and the protocol was '1 shot' and you could
detect this but this isn't the case with all the fragments(consistency is
nowhere to be found in this system!) and often the client expects a return
fragment back down the same stream (in the same transaction).
The protocol is very http in style.


<snip>

HTTP in style except without the Content-Length :(

If these are meant to be proper XML fragments, could you not just read
until you've got a full XML fragment? In other words, if you get:

<foo>
<bar>
baz
</bar>
</foo>

then as soon as you see </foo> you know you're finished, don't you? Or
could there be another foo element?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
mike b <te**@mike.here> wrote:
I have been working with what i believe is, an poorly designed
client/protocol, and this is causing me no end of headaches determining the end of a 'fragment'. The header of each fragment ends in a constant fasion (single line consisting of a carriage return) however the payload afterwards containing xml fragment does not end in a consistent fasion, this would be fine if the stream was closed and the protocol was '1 shot' and you could detect this but this isn't the case with all the fragments(consistency is nowhere to be found in this system!) and often the client expects a return fragment back down the same stream (in the same transaction).
The protocol is very http in style.


<snip>

HTTP in style except without the Content-Length :(

If these are meant to be proper XML fragments, could you not just read
until you've got a full XML fragment? In other words, if you get:

<foo>
<bar>
baz
</bar>
</foo>

then as soon as you see </foo> you know you're finished, don't you? Or
could there be another foo element?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


yeah the content the Content-Length would be such a boon

I honestly cannot believe I didn't think of the XML checking method ... :(

many thanks for the prompt reply and fresh idea!

thanks
Mike
Nov 15 '05 #3

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

Similar topics

1
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....
4
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
0
by: Abubakar | last post by:
Hi, try { int x = ns.Read(readbuffer, 0, readbuffer.Length); } catch (System.IO.IOException ioexception) { UINotifications.ServerMessageDisplay(ioexception.ToString( )); }
6
by: Ryan | last post by:
Hi, I am confused with how NetworkStream works. My application needs to handle heavy requests sent through TCP socket connection. I use NetworkStream.Read method to get the stream...
3
by: codeman | last post by:
Hi all Lets say we have two tables: Customer: Customer_number : Decimal(15) Name : Char(30) Purchase: Purchase_number : Decimal(15)
10
by: rup | last post by:
Hello, This is my first application on socket programming in vc++. I am facing problem that how to make connection to server, & make GET/POST request by HTTP. Please help me. Its urgent.......
0
by: Abu Alaz | last post by:
Hello all I have tow question in C# the first question 1-how show my MAC Address of my PC because i working in network programming ,then i have each Client send your MAC Address to more...
7
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...

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.