Sending XML data via socket

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

    #1

    Sending XML data via socket

    I am sending an XML data from not dontnet process to a .Net via socket
    listener.
    Here is a data sample:
    <VFPData>
    <serverdata>
    <coderun>update Floor</coderun>
    <area>MD2</area>
    <zone>BOXING</zone>
    <status>Running </status>
    <job>1000139233 </job>
    <sku>02219</sku>
    <finished>88</finished>
    </serverdata>
    </VFPData>
    My problem is that sometimes it come out of a listner like this:
    <VFPData>
    <serverdata>
    <coderun>update Floor</coderun>
    <area>MD2</area>
    <zone>BOXING</zone>
    <status>Running </status>
    <job>1000139233 </job>
    <sku>02219</sku>
    <finished>88</finished>
    </serverda
    ta>
    </VFPData>
    or like this:
    <VFPData>
    <serverdata>
    <coderun>update Floor</coderun>
    <area>MD2</area>
    <zone>BOXING</zone>
    <status>Running </status>
    <job>1000139233 </job>
    <sku>02219</sku>
    <fini
    shed>92</finished>
    </serverdata>
    </VFPData>
    I am sure that the sending process sends data in a proper format all the
    time.
    What do I need to do to keep XML well formed?

    Thanks


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Sending XML data via socket

    Markgoldin,

    What are the line breaks representing? Are there actual line breaks
    that are being injected into the stream somehow, or does it symbolize the
    breaks in what you are reading from the server?

    What is the code that you are using to call from the stream? Are you
    checking the return value to see that all of the bytes that you requested to
    read are actually being read, or are you just assuming that the bytes are
    being read completely?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
    news:u4Lqvel8IH A.3928@TK2MSFTN GP04.phx.gbl...
    >I am sending an XML data from not dontnet process to a .Net via socket
    >listener.
    Here is a data sample:
    <VFPData>
    <serverdata>
    <coderun>update Floor</coderun>
    <area>MD2</area>
    <zone>BOXING</zone>
    <status>Running </status>
    <job>1000139233 </job>
    <sku>02219</sku>
    <finished>88</finished>
    </serverdata>
    </VFPData>
    My problem is that sometimes it come out of a listner like this:
    <VFPData>
    <serverdata>
    <coderun>update Floor</coderun>
    <area>MD2</area>
    <zone>BOXING</zone>
    <status>Running </status>
    <job>1000139233 </job>
    <sku>02219</sku>
    <finished>88</finished>
    </serverda
    ta>
    </VFPData>
    or like this:
    <VFPData>
    <serverdata>
    <coderun>update Floor</coderun>
    <area>MD2</area>
    <zone>BOXING</zone>
    <status>Running </status>
    <job>1000139233 </job>
    <sku>02219</sku>
    <fini
    shed>92</finished>
    </serverdata>
    </VFPData>
    I am sure that the sending process sends data in a proper format all the
    time.
    What do I need to do to keep XML well formed?
    >
    Thanks
    >

    Comment

    • Markgoldin

      #3
      Re: Sending XML data via socket

      <Are there actual line breaks
      that are being injected into the stream somehow
      Yes, I think that is what happens. I am not sending line breaks at these
      positions.

      <What is the code that you are using to call from the stream?
      I have my code posted in "Multiple socket clients" message.
      If you can't see it I will post it again.

      Thanks alot for help.


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:e4K5Nil8IH A.1200@TK2MSFTN GP04.phx.gbl...
      Markgoldin,
      >
      What are the line breaks representing? Are there actual line breaks
      that are being injected into the stream somehow, or does it symbolize the
      breaks in what you are reading from the server?
      >
      What is the code that you are using to call from the stream? Are you
      checking the return value to see that all of the bytes that you requested
      to read are actually being read, or are you just assuming that the bytes
      are being read completely?
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
      news:u4Lqvel8IH A.3928@TK2MSFTN GP04.phx.gbl...
      >>I am sending an XML data from not dontnet process to a .Net via socket
      >>listener.
      >Here is a data sample:
      ><VFPData>
      > <serverdata>
      > <coderun>update Floor</coderun>
      > <area>MD2</area>
      > <zone>BOXING</zone>
      > <status>Running </status>
      > <job>1000139233 </job>
      > <sku>02219</sku>
      > <finished>88</finished>
      > </serverdata>
      ></VFPData>
      >My problem is that sometimes it come out of a listner like this:
      ><VFPData>
      > <serverdata>
      > <coderun>update Floor</coderun>
      > <area>MD2</area>
      > <zone>BOXING</zone>
      > <status>Running </status>
      > <job>1000139233 </job>
      > <sku>02219</sku>
      > <finished>88</finished>
      > </serverda
      >ta>
      ></VFPData>
      >or like this:
      ><VFPData>
      > <serverdata>
      > <coderun>update Floor</coderun>
      > <area>MD2</area>
      > <zone>BOXING</zone>
      > <status>Running </status>
      > <job>1000139233 </job>
      > <sku>02219</sku>
      > <fini
      >shed>92</finished>
      > </serverdata>
      ></VFPData>
      >I am sure that the sending process sends data in a proper format all the
      >time.
      >What do I need to do to keep XML well formed?
      >>
      >Thanks
      >>
      >
      >

      Comment

      • Ignacio Machin ( .NET/ C# MVP )

        #4
        Re: Sending XML data via socket

        On Jul 30, 11:19 am, "Markgoldin " <markgoldin_2.. .@yahoo.comwrot e:
        I am sending an XML data from not dontnet process to a .Net via socket
        listener.
        Here is a data sample:
        <VFPData>
                <serverdata>
                        <coderun>update Floor</coderun>
                        <area>MD2</area>
                        <zone>BOXING</zone>
                        <status>Running </status>
                        <job>1000139233 </job>
                        <sku>02219</sku>
                        <finished>88</finished>
                </serverdata>
        </VFPData>
        My problem is that sometimes it come out of a listner like this:
        <VFPData>
                <serverdata>
                        <coderun>update Floor</coderun>
                        <area>MD2</area>
                        <zone>BOXING</zone>
                        <status>Running </status>
                        <job>1000139233 </job>
                        <sku>02219</sku>
                        <finished>88</finished>
                </serverda
        ta>
        </VFPData>
        or like this:
        <VFPData>
                <serverdata>
                        <coderun>update Floor</coderun>
                        <area>MD2</area>
                        <zone>BOXING</zone>
                        <status>Running </status>
                        <job>1000139233 </job>
                        <sku>02219</sku>
                        <fini
        shed>92</finished>
                </serverdata>
        </VFPData>
        I am sure that the sending process sends data in a proper format all the
        time.
        What do I need to do to keep XML well formed?
        >
        Thanks
        can you post the code you are using to get it from the network stream?
        Are you calling WriteLine somewhere?

        Comment

        • Markgoldin

          #5
          Re: Sending XML data via socket

          My code is posted in my message "Multiple socket clients".
          Let me know if you can't see it I will post it here.

          Thanks for the help.

          "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin @gmail.comwrote in
          message
          news:c7b6701c-f7b5-4d67-a796-105f2c6cf633@x4 1g2000hsb.googl egroups.com...
          On Jul 30, 11:19 am, "Markgoldin " <markgoldin_2.. .@yahoo.comwrot e:
          I am sending an XML data from not dontnet process to a .Net via socket
          listener.
          Here is a data sample:
          <VFPData>
          <serverdata>
          <coderun>update Floor</coderun>
          <area>MD2</area>
          <zone>BOXING</zone>
          <status>Running </status>
          <job>1000139233 </job>
          <sku>02219</sku>
          <finished>88</finished>
          </serverdata>
          </VFPData>
          My problem is that sometimes it come out of a listner like this:
          <VFPData>
          <serverdata>
          <coderun>update Floor</coderun>
          <area>MD2</area>
          <zone>BOXING</zone>
          <status>Running </status>
          <job>1000139233 </job>
          <sku>02219</sku>
          <finished>88</finished>
          </serverda
          ta>
          </VFPData>
          or like this:
          <VFPData>
          <serverdata>
          <coderun>update Floor</coderun>
          <area>MD2</area>
          <zone>BOXING</zone>
          <status>Running </status>
          <job>1000139233 </job>
          <sku>02219</sku>
          <fini
          shed>92</finished>
          </serverdata>
          </VFPData>
          I am sure that the sending process sends data in a proper format all the
          time.
          What do I need to do to keep XML well formed?
          >
          Thanks
          can you post the code you are using to get it from the network stream?
          Are you calling WriteLine somewhere?


          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Sending XML data via socket

            Generally, you should post the code in the same thread. The reason for
            this is that there can be a LOT of threads in a newsgroup and a lot of
            messages.

            Looking at the code you posted, how do you know how many total bytes
            make up the message? In other words, when a message is sent, when do you
            know the XML ends? In a situation like this, you should be sending the
            length of the message first to indicate the number of bytes that make up the
            message, and then read that number of bytes.

            Also, it's not guaranteed that the Stream will return the number of
            bytes that you request to read. Because of that, you might have to call it
            multiple times. Check out Jon Skeet's site which goes into more detail:



            --
            - Nicholas Paldino [.NET/C# MVP]
            - mvp@spam.guard. caspershouse.co m

            "Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
            news:OCZH7ml8IH A.4608@TK2MSFTN GP06.phx.gbl...
            <Are there actual line breaks
            >that are being injected into the stream somehow
            Yes, I think that is what happens. I am not sending line breaks at these
            positions.
            >
            <What is the code that you are using to call from the stream?
            I have my code posted in "Multiple socket clients" message.
            If you can't see it I will post it again.
            >
            Thanks alot for help.
            >
            >
            "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
            in message news:e4K5Nil8IH A.1200@TK2MSFTN GP04.phx.gbl...
            >Markgoldin,
            >>
            > What are the line breaks representing? Are there actual line breaks
            >that are being injected into the stream somehow, or does it symbolize the
            >breaks in what you are reading from the server?
            >>
            > What is the code that you are using to call from the stream? Are you
            >checking the return value to see that all of the bytes that you requested
            >to read are actually being read, or are you just assuming that the bytes
            >are being read completely?
            >>
            >>
            >--
            > - Nicholas Paldino [.NET/C# MVP]
            > - mvp@spam.guard. caspershouse.co m
            >>
            >"Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
            >news:u4Lqvel8I HA.3928@TK2MSFT NGP04.phx.gbl.. .
            >>>I am sending an XML data from not dontnet process to a .Net via socket
            >>>listener.
            >>Here is a data sample:
            >><VFPData>
            >> <serverdata>
            >> <coderun>update Floor</coderun>
            >> <area>MD2</area>
            >> <zone>BOXING</zone>
            >> <status>Running </status>
            >> <job>1000139233 </job>
            >> <sku>02219</sku>
            >> <finished>88</finished>
            >> </serverdata>
            >></VFPData>
            >>My problem is that sometimes it come out of a listner like this:
            >><VFPData>
            >> <serverdata>
            >> <coderun>update Floor</coderun>
            >> <area>MD2</area>
            >> <zone>BOXING</zone>
            >> <status>Running </status>
            >> <job>1000139233 </job>
            >> <sku>02219</sku>
            >> <finished>88</finished>
            >> </serverda
            >>ta>
            >></VFPData>
            >>or like this:
            >><VFPData>
            >> <serverdata>
            >> <coderun>update Floor</coderun>
            >> <area>MD2</area>
            >> <zone>BOXING</zone>
            >> <status>Running </status>
            >> <job>1000139233 </job>
            >> <sku>02219</sku>
            >> <fini
            >>shed>92</finished>
            >> </serverdata>
            >></VFPData>
            >>I am sure that the sending process sends data in a proper format all the
            >>time.
            >>What do I need to do to keep XML well formed?
            >>>
            >>Thanks
            >>>
            >>
            >>
            >
            >

            Comment

            • Markgoldin

              #7
              Re: Sending XML data via socket

              What I am trying to do is to read the whole lot into a buffer.
              Can I somehow read untill a special character is met? Something like char
              13?
              That way I dont have to send a number of bytes to read.

              Thanks

              "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
              message news:e1qyWyl8IH A.616@TK2MSFTNG P02.phx.gbl...
              Generally, you should post the code in the same thread. The reason for
              this is that there can be a LOT of threads in a newsgroup and a lot of
              messages.
              >
              Looking at the code you posted, how do you know how many total bytes
              make up the message? In other words, when a message is sent, when do you
              know the XML ends? In a situation like this, you should be sending the
              length of the message first to indicate the number of bytes that make up
              the message, and then read that number of bytes.
              >
              Also, it's not guaranteed that the Stream will return the number of
              bytes that you request to read. Because of that, you might have to call
              it multiple times. Check out Jon Skeet's site which goes into more
              detail:
              >

              >
              --
              - Nicholas Paldino [.NET/C# MVP]
              - mvp@spam.guard. caspershouse.co m
              >
              "Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
              news:OCZH7ml8IH A.4608@TK2MSFTN GP06.phx.gbl...
              ><Are there actual line breaks
              >>that are being injected into the stream somehow
              >Yes, I think that is what happens. I am not sending line breaks at these
              >positions.
              >>
              ><What is the code that you are using to call from the stream?
              >I have my code posted in "Multiple socket clients" message.
              >If you can't see it I will post it again.
              >>
              >Thanks alot for help.
              >>
              >>
              >"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
              >in message news:e4K5Nil8IH A.1200@TK2MSFTN GP04.phx.gbl...
              >>Markgoldin,
              >>>
              >> What are the line breaks representing? Are there actual line breaks
              >>that are being injected into the stream somehow, or does it symbolize
              >>the breaks in what you are reading from the server?
              >>>
              >> What is the code that you are using to call from the stream? Are you
              >>checking the return value to see that all of the bytes that you
              >>requested to read are actually being read, or are you just assuming that
              >>the bytes are being read completely?
              >>>
              >>>
              >>--
              >> - Nicholas Paldino [.NET/C# MVP]
              >> - mvp@spam.guard. caspershouse.co m
              >>>
              >>"Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
              >>news:u4Lqvel8 IHA.3928@TK2MSF TNGP04.phx.gbl. ..
              >>>>I am sending an XML data from not dontnet process to a .Net via socket
              >>>>listener.
              >>>Here is a data sample:
              >>><VFPData>
              >>> <serverdata>
              >>> <coderun>update Floor</coderun>
              >>> <area>MD2</area>
              >>> <zone>BOXING</zone>
              >>> <status>Running </status>
              >>> <job>1000139233 </job>
              >>> <sku>02219</sku>
              >>> <finished>88</finished>
              >>> </serverdata>
              >>></VFPData>
              >>>My problem is that sometimes it come out of a listner like this:
              >>><VFPData>
              >>> <serverdata>
              >>> <coderun>update Floor</coderun>
              >>> <area>MD2</area>
              >>> <zone>BOXING</zone>
              >>> <status>Running </status>
              >>> <job>1000139233 </job>
              >>> <sku>02219</sku>
              >>> <finished>88</finished>
              >>> </serverda
              >>>ta>
              >>></VFPData>
              >>>or like this:
              >>><VFPData>
              >>> <serverdata>
              >>> <coderun>update Floor</coderun>
              >>> <area>MD2</area>
              >>> <zone>BOXING</zone>
              >>> <status>Running </status>
              >>> <job>1000139233 </job>
              >>> <sku>02219</sku>
              >>> <fini
              >>>shed>92</finished>
              >>> </serverdata>
              >>></VFPData>
              >>>I am sure that the sending process sends data in a proper format all
              >>>the time.
              >>>What do I need to do to keep XML well formed?
              >>>>
              >>>Thanks
              >>>>
              >>>
              >>>
              >>
              >>
              >
              >

              Comment

              • Nicholas Paldino [.NET/C# MVP]

                #8
                Re: Sending XML data via socket

                Markgoldin,

                You could, but the problem with that is that you would have to read from
                the stream one character at a time (or rather, one byte at a time,
                converting to a character when you have enough bytes). The reason for this
                is that if you have say, 10 characters left in the stream, and you issue a
                read for 100 bytes, the call will block until more bytes come in on the
                stream.

                This is why putting the length prefix in is a better option.

                --
                - Nicholas Paldino [.NET/C# MVP]
                - mvp@spam.guard. caspershouse.co m

                "Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
                news:ebK30Am8IH A.1204@TK2MSFTN GP04.phx.gbl...
                What I am trying to do is to read the whole lot into a buffer.
                Can I somehow read untill a special character is met? Something like char
                13?
                That way I dont have to send a number of bytes to read.
                >
                Thanks
                >
                "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
                in message news:e1qyWyl8IH A.616@TK2MSFTNG P02.phx.gbl...
                > Generally, you should post the code in the same thread. The reason
                >for this is that there can be a LOT of threads in a newsgroup and a lot
                >of messages.
                >>
                > Looking at the code you posted, how do you know how many total bytes
                >make up the message? In other words, when a message is sent, when do you
                >know the XML ends? In a situation like this, you should be sending the
                >length of the message first to indicate the number of bytes that make up
                >the message, and then read that number of bytes.
                >>
                > Also, it's not guaranteed that the Stream will return the number of
                >bytes that you request to read. Because of that, you might have to call
                >it multiple times. Check out Jon Skeet's site which goes into more
                >detail:
                >>
                >http://www.yoda.arachsys.com/csharp/readbinary.html
                >>
                >--
                > - Nicholas Paldino [.NET/C# MVP]
                > - mvp@spam.guard. caspershouse.co m
                >>
                >"Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
                >news:OCZH7ml8I HA.4608@TK2MSFT NGP06.phx.gbl.. .
                >><Are there actual line breaks
                >>>that are being injected into the stream somehow
                >>Yes, I think that is what happens. I am not sending line breaks at these
                >>positions.
                >>>
                >><What is the code that you are using to call from the stream?
                >>I have my code posted in "Multiple socket clients" message.
                >>If you can't see it I will post it again.
                >>>
                >>Thanks alot for help.
                >>>
                >>>
                >>"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
                >>in message news:e4K5Nil8IH A.1200@TK2MSFTN GP04.phx.gbl...
                >>>Markgoldin ,
                >>>>
                >>> What are the line breaks representing? Are there actual line breaks
                >>>that are being injected into the stream somehow, or does it symbolize
                >>>the breaks in what you are reading from the server?
                >>>>
                >>> What is the code that you are using to call from the stream? Are
                >>>you checking the return value to see that all of the bytes that you
                >>>requested to read are actually being read, or are you just assuming
                >>>that the bytes are being read completely?
                >>>>
                >>>>
                >>>--
                >>> - Nicholas Paldino [.NET/C# MVP]
                >>> - mvp@spam.guard. caspershouse.co m
                >>>>
                >>>"Markgoldi n" <markgoldin_200 0@yahoo.comwrot e in message
                >>>news:u4Lqvel 8IHA.3928@TK2MS FTNGP04.phx.gbl ...
                >>>>>I am sending an XML data from not dontnet process to a .Net via socket
                >>>>>listener .
                >>>>Here is a data sample:
                >>>><VFPData>
                >>>> <serverdata>
                >>>> <coderun>update Floor</coderun>
                >>>> <area>MD2</area>
                >>>> <zone>BOXING</zone>
                >>>> <status>Running </status>
                >>>> <job>1000139233 </job>
                >>>> <sku>02219</sku>
                >>>> <finished>88</finished>
                >>>> </serverdata>
                >>>></VFPData>
                >>>>My problem is that sometimes it come out of a listner like this:
                >>>><VFPData>
                >>>> <serverdata>
                >>>> <coderun>update Floor</coderun>
                >>>> <area>MD2</area>
                >>>> <zone>BOXING</zone>
                >>>> <status>Running </status>
                >>>> <job>1000139233 </job>
                >>>> <sku>02219</sku>
                >>>> <finished>88</finished>
                >>>> </serverda
                >>>>ta>
                >>>></VFPData>
                >>>>or like this:
                >>>><VFPData>
                >>>> <serverdata>
                >>>> <coderun>update Floor</coderun>
                >>>> <area>MD2</area>
                >>>> <zone>BOXING</zone>
                >>>> <status>Running </status>
                >>>> <job>1000139233 </job>
                >>>> <sku>02219</sku>
                >>>> <fini
                >>>>shed>92</finished>
                >>>> </serverdata>
                >>>></VFPData>
                >>>>I am sure that the sending process sends data in a proper format all
                >>>>the time.
                >>>>What do I need to do to keep XML well formed?
                >>>>>
                >>>>Thanks
                >>>>>
                >>>>
                >>>>
                >>>
                >>>
                >>
                >>
                >
                >

                Comment

                • Ignacio Machin ( .NET/ C# MVP )

                  #9
                  Re: Sending XML data via socket

                  On Jul 30, 11:46 am, "Markgoldin " <markgoldin_2.. .@yahoo.comwrot e:
                  My code is posted in my message "Multiple socket clients".
                  Let me know if you can't see it I will post it here.
                  >
                  Thanks for the help.
                  >
                  "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mac... @gmail.comwrote in
                  messagenews:c7b 6701c-f7b5-4d67-a796-105f2c6cf633@x4 1g2000hsb.googl egroups..com...
                  On Jul 30, 11:19 am, "Markgoldin " <markgoldin_2.. .@yahoo.comwrot e:
                  >
                  >
                  >
                  >
                  >
                  I am sending an XML data from not dontnet process to a .Net via socket
                  listener.
                  Here is a data sample:
                  <VFPData>
                  <serverdata>
                  <coderun>update Floor</coderun>
                  <area>MD2</area>
                  <zone>BOXING</zone>
                  <status>Running </status>
                  <job>1000139233 </job>
                  <sku>02219</sku>
                  <finished>88</finished>
                  </serverdata>
                  </VFPData>
                  My problem is that sometimes it come out of a listner like this:
                  <VFPData>
                  <serverdata>
                  <coderun>update Floor</coderun>
                  <area>MD2</area>
                  <zone>BOXING</zone>
                  <status>Running </status>
                  <job>1000139233 </job>
                  <sku>02219</sku>
                  <finished>88</finished>
                  </serverda
                  ta>
                  </VFPData>
                  or like this:
                  <VFPData>
                  <serverdata>
                  <coderun>update Floor</coderun>
                  <area>MD2</area>
                  <zone>BOXING</zone>
                  <status>Running </status>
                  <job>1000139233 </job>
                  <sku>02219</sku>
                  <fini
                  shed>92</finished>
                  </serverdata>
                  </VFPData>
                  I am sure that the sending process sends data in a proper format all the
                  time.
                  What do I need to do to keep XML well formed?
                  >
                  Thanks
                  >
                  can you post the code you are using to get it from the network stream?
                  Are you calling WriteLine somewhere?- Hide quoted text -
                  >
                  - Show quoted text -
                  post the code here

                  Comment

                  • Markgoldin

                    #10
                    Re: Sending XML data via socket

                    Here is code I am using to create a socket listener:
                    public void Run()

                    {

                    go = true;

                    Random rand = new Random();

                    // Buffer for reading data

                    Byte[] bytes = new Byte[1024];

                    String data = null;

                    while (go)

                    {

                    TcpClient tcpc = FromAnotherClas s.tcpl.AcceptTc pClient(); //accept
                    connection

                    data = null;

                    // Get a stream object for reading and writing

                    NetworkStream stream = tcpc.GetStream( );

                    // Loop to receive all the data sent by the client.

                    int i;

                    while ((i = stream.Read(byt es, 0, bytes.Length)) != 0)

                    {

                    // Translate data bytes to a ASCII string.

                    data = System.Text.Enc oding.ASCII.Get String(bytes, 0, i);

                    // Process the data sent by the client.

                    if (data != "")

                    {

                    System.Console. WriteLine(data) ;

                    }

                    }

                    Thread.Sleep(10 00 + rand.Next(2000) );

                    }

                    }

                    "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin @gmail.comwrote in
                    message
                    news:f8d2e924-e729-4f39-a4cc-62d0859c68d5@r6 6g2000hsg.googl egroups.com...
                    On Jul 30, 11:46 am, "Markgoldin " <markgoldin_2.. .@yahoo.comwrot e:
                    My code is posted in my message "Multiple socket clients".
                    Let me know if you can't see it I will post it here.
                    >
                    Thanks for the help.
                    >
                    "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mac... @gmail.comwrote in
                    messagenews:c7b 6701c-f7b5-4d67-a796-105f2c6cf633@x4 1g2000hsb.googl egroups.com...
                    On Jul 30, 11:19 am, "Markgoldin " <markgoldin_2.. .@yahoo.comwrot e:
                    >
                    >
                    >
                    >
                    >
                    I am sending an XML data from not dontnet process to a .Net via socket
                    listener.
                    Here is a data sample:
                    <VFPData>
                    <serverdata>
                    <coderun>update Floor</coderun>
                    <area>MD2</area>
                    <zone>BOXING</zone>
                    <status>Running </status>
                    <job>1000139233 </job>
                    <sku>02219</sku>
                    <finished>88</finished>
                    </serverdata>
                    </VFPData>
                    My problem is that sometimes it come out of a listner like this:
                    <VFPData>
                    <serverdata>
                    <coderun>update Floor</coderun>
                    <area>MD2</area>
                    <zone>BOXING</zone>
                    <status>Running </status>
                    <job>1000139233 </job>
                    <sku>02219</sku>
                    <finished>88</finished>
                    </serverda
                    ta>
                    </VFPData>
                    or like this:
                    <VFPData>
                    <serverdata>
                    <coderun>update Floor</coderun>
                    <area>MD2</area>
                    <zone>BOXING</zone>
                    <status>Running </status>
                    <job>1000139233 </job>
                    <sku>02219</sku>
                    <fini
                    shed>92</finished>
                    </serverdata>
                    </VFPData>
                    I am sure that the sending process sends data in a proper format all the
                    time.
                    What do I need to do to keep XML well formed?
                    >
                    Thanks
                    >
                    can you post the code you are using to get it from the network stream?
                    Are you calling WriteLine somewhere?- Hide quoted text -
                    >
                    - Show quoted text -
                    post the code here


                    Comment

                    • Markgoldin

                      #11
                      Re: Sending XML data via socket

                      Ok, I looked int a link you have provided.
                      I am trying to adapt one of the examples from that link. Here is my code:

                      TcpClient tcpc = DataAdapterLaun cher.tcpl.Accep tTcpClient(); //accept
                      connection
                      // Get a stream object for reading and writing
                      NetworkStream stream = tcpc.GetStream( );
                      Byte[] buffer = new Byte[32768];
                      // Loop to receive all the data sent by the client.
                      int chunk;
                      int read = 0;
                      while ((chunk = stream.Read(buf fer, read, buffer.Length - read)) != 0)
                      {
                      read += chunk;
                      System.Console. WriteLine(read) ;
                      // If we've reached the end of our buffer, check to see if there's
                      // any more information
                      if (read == buffer.Length)
                      {
                      int nextByte = stream.ReadByte ();
                      System.Console. WriteLine("read 2");
                      // End of stream? If so, we're done
                      if (nextByte == -1)
                      {
                      // Process the data sent by the client.
                      // Translate data bytes to a ASCII string.
                      System.Console. WriteLine("read 4");
                      break;
                      }
                      // Nope. Resize the buffer, put in the byte we've just
                      // read, and continue
                      byte[] newBuffer = new byte[buffer.Length * 2];
                      Array.Copy(buff er, newBuffer, buffer.Length);
                      newBuffer[read] = (byte)nextByte;
                      buffer = newBuffer;
                      read++;
                      System.Console. WriteLine("read 3");
                      }
                      }

                      In the Console it only says "read".


                      Here is the code fro the link:
                      /// <summary>
                      /// Reads data from a stream until the end is reached. The
                      /// data is returned as a byte array. An IOException is
                      /// thrown if any of the underlying IO calls fail.
                      /// </summary>
                      /// <param name="stream">T he stream to read data from</param>
                      /// <param name="initialLe ngth">The initial buffer length</param>
                      public static byte[] ReadFully (Stream stream, int initialLength)
                      {
                      // If we've been passed an unhelpful initial length, just
                      // use 32K.
                      if (initialLength < 1)
                      {
                      initialLength = 32768;
                      }

                      byte[] buffer = new byte[initialLength];
                      int read=0;

                      int chunk;
                      while ( (chunk = stream.Read(buf fer, read, buffer.Length-read)) 0)
                      {
                      read += chunk;

                      // If we've reached the end of our buffer, check to see if there's
                      // any more information
                      if (read == buffer.Length)
                      {
                      int nextByte = stream.ReadByte ();

                      // End of stream? If so, we're done
                      if (nextByte==-1)
                      {
                      return buffer;
                      }

                      // Nope. Resize the buffer, put in the byte we've just
                      // read, and continue
                      byte[] newBuffer = new byte[buffer.Length*2];
                      Array.Copy(buff er, newBuffer, buffer.Length);
                      newBuffer[read]=(byte)nextByte ;
                      buffer = newBuffer;
                      read++;
                      }
                      }
                      // Buffer is now too big. Shrink it.
                      byte[] ret = new byte[read];
                      Array.Copy(buff er, ret, read);
                      return ret;
                      }
                      I jsut can't figure out where my code is wrong.Can you please provide
                      help?Thanks.
                      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
                      message news:e1qyWyl8IH A.616@TK2MSFTNG P02.phx.gbl...
                      Generally, you should post the code in the same thread. The reason for
                      this is that there can be a LOT of threads in a newsgroup and a lot of
                      messages.
                      >
                      Looking at the code you posted, how do you know how many total bytes
                      make up the message? In other words, when a message is sent, when do you
                      know the XML ends? In a situation like this, you should be sending the
                      length of the message first to indicate the number of bytes that make up
                      the message, and then read that number of bytes.
                      >
                      Also, it's not guaranteed that the Stream will return the number of
                      bytes that you request to read. Because of that, you might have to call
                      it multiple times. Check out Jon Skeet's site which goes into more
                      detail:
                      >

                      >
                      --
                      - Nicholas Paldino [.NET/C# MVP]
                      - mvp@spam.guard. caspershouse.co m
                      >
                      "Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
                      news:OCZH7ml8IH A.4608@TK2MSFTN GP06.phx.gbl...
                      ><Are there actual line breaks
                      >>that are being injected into the stream somehow
                      >Yes, I think that is what happens. I am not sending line breaks at these
                      >positions.
                      >>
                      ><What is the code that you are using to call from the stream?
                      >I have my code posted in "Multiple socket clients" message.
                      >If you can't see it I will post it again.
                      >>
                      >Thanks alot for help.
                      >>
                      >>
                      >"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
                      >in message news:e4K5Nil8IH A.1200@TK2MSFTN GP04.phx.gbl...
                      >>Markgoldin,
                      >>>
                      >> What are the line breaks representing? Are there actual line breaks
                      >>that are being injected into the stream somehow, or does it symbolize
                      >>the breaks in what you are reading from the server?
                      >>>
                      >> What is the code that you are using to call from the stream? Are you
                      >>checking the return value to see that all of the bytes that you
                      >>requested to read are actually being read, or are you just assuming that
                      >>the bytes are being read completely?
                      >>>
                      >>>
                      >>--
                      >> - Nicholas Paldino [.NET/C# MVP]
                      >> - mvp@spam.guard. caspershouse.co m
                      >>>
                      >>"Markgoldin " <markgoldin_200 0@yahoo.comwrot e in message
                      >>news:u4Lqvel8 IHA.3928@TK2MSF TNGP04.phx.gbl. ..
                      >>>>I am sending an XML data from not dontnet process to a .Net via socket
                      >>>>listener.
                      >>>Here is a data sample:
                      >>><VFPData>
                      >>> <serverdata>
                      >>> <coderun>update Floor</coderun>
                      >>> <area>MD2</area>
                      >>> <zone>BOXING</zone>
                      >>> <status>Running </status>
                      >>> <job>1000139233 </job>
                      >>> <sku>02219</sku>
                      >>> <finished>88</finished>
                      >>> </serverdata>
                      >>></VFPData>
                      >>>My problem is that sometimes it come out of a listner like this:
                      >>><VFPData>
                      >>> <serverdata>
                      >>> <coderun>update Floor</coderun>
                      >>> <area>MD2</area>
                      >>> <zone>BOXING</zone>
                      >>> <status>Running </status>
                      >>> <job>1000139233 </job>
                      >>> <sku>02219</sku>
                      >>> <finished>88</finished>
                      >>> </serverda
                      >>>ta>
                      >>></VFPData>
                      >>>or like this:
                      >>><VFPData>
                      >>> <serverdata>
                      >>> <coderun>update Floor</coderun>
                      >>> <area>MD2</area>
                      >>> <zone>BOXING</zone>
                      >>> <status>Running </status>
                      >>> <job>1000139233 </job>
                      >>> <sku>02219</sku>
                      >>> <fini
                      >>>shed>92</finished>
                      >>> </serverdata>
                      >>></VFPData>
                      >>>I am sure that the sending process sends data in a proper format all
                      >>>the time.
                      >>>What do I need to do to keep XML well formed?
                      >>>>
                      >>>Thanks
                      >>>>
                      >>>
                      >>>
                      >>
                      >>
                      >
                      >

                      Comment

                      Working...