473,320 Members | 1,884 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,320 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 1553
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.