NetworkStream & inconsistent protocols

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike b

    #1

    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(consi stency 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










  • Jon Skeet [C# MVP]

    #2
    Re: NetworkStream & inconsistent protocols

    mike b <test@mike.here > wrote:[color=blue]
    > 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(consi stency 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.[/color]

    <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 - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • mike b

      #3
      Re: NetworkStream &amp; inconsistent protocols

      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.19ec90 c67bc1a59998980 d@msnews.micros oft.com...[color=blue]
      > mike b <test@mike.here > wrote:[color=green]
      > > I have been working with what i believe is, an poorly designed
      > > client/protocol, and this is causing me no end of headaches determining[/color][/color]
      the[color=blue][color=green]
      > > end of a 'fragment'. The header of each fragment ends in a constant[/color][/color]
      fasion[color=blue][color=green]
      > > (single line consisting of a carriage return) however the payload[/color][/color]
      afterwards[color=blue][color=green]
      > > containing xml fragment does not end in a consistent fasion, this would[/color][/color]
      be[color=blue][color=green]
      > > fine if the stream was closed and the protocol was '1 shot' and you[/color][/color]
      could[color=blue][color=green]
      > > detect this but this isn't the case with all the fragments(consi stency[/color][/color]
      is[color=blue][color=green]
      > > nowhere to be found in this system!) and often the client expects a[/color][/color]
      return[color=blue][color=green]
      > > fragment back down the same stream (in the same transaction).
      > > The protocol is very http in style.[/color]
      >
      > <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 - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]

      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


      Comment

      Working...