Sending additional info with byte array with sockets

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

    Sending additional info with byte array with sockets

    Hello,

    I want to send an additional info with byte array wiith sockets as "one
    packet".
    I know how to send the byte array by himself, but how can I send the
    additional info with it at the same time (as one packet)?

    thx for yout answers.


  • Jon Skeet [C# MVP]

    #2
    Re: Sending additional info with byte array with sockets

    TomHL <TomHL@discussi ons.microsoft.c om> wrote:[color=blue]
    > I want to send an additional info with byte array wiith sockets as "one
    > packet".
    > I know how to send the byte array by himself, but how can I send the
    > additional info with it at the same time (as one packet)?
    >
    > thx for yout answers.[/color]

    Firstly, you can't guarantee that information you send on a socket will
    be sent in a single packet, and you shouldn't rely on it. Sockets give
    *streams* of data, and that's how the information should be thought of.

    Now, as to sending "additional information" - that will have to be part
    of the data sent. You could, for instance, have a sort of "header"
    section before the data, potentially including the length of the data
    as well as other bits of information. It will be part of the data
    received, however, so the other end will need to know that there'll be
    that header section first.

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • TomHL

      #3
      Re: Sending additional info with byte array with sockets

      Hi Jon, thx for your answer.
      How do I cretae and send the Header with the byte array (don't forget that I
      need to send it attached to the byte array :-))?

      "Jon Skeet [C# MVP]" wrote:
      [color=blue]
      > TomHL <TomHL@discussi ons.microsoft.c om> wrote:[color=green]
      > > I want to send an additional info with byte array wiith sockets as "one
      > > packet".
      > > I know how to send the byte array by himself, but how can I send the
      > > additional info with it at the same time (as one packet)?
      > >
      > > thx for yout answers.[/color]
      >
      > Firstly, you can't guarantee that information you send on a socket will
      > be sent in a single packet, and you shouldn't rely on it. Sockets give
      > *streams* of data, and that's how the information should be thought of.
      >
      > Now, as to sending "additional information" - that will have to be part
      > of the data sent. You could, for instance, have a sort of "header"
      > section before the data, potentially including the length of the data
      > as well as other bits of information. It will be part of the data
      > received, however, so the other end will need to know that there'll be
      > that header section first.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      > If replying to the group, please do not mail me too
      >[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Sending additional info with byte array with sockets

        TomHL <TomHL@discussi ons.microsoft.c om> wrote:[color=blue]
        > Hi Jon, thx for your answer.
        > How do I cretae and send the Header with the byte array (don't forget that I
        > need to send it attached to the byte array :-))?[/color]

        You don't need to send it "attached" to the byte array. Just send the
        header (as a byte array), then send the byte array itself. Don't forget
        it's just a stream of data when all is said and done.

        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        • TomHL

          #5
          Re: Sending additional info with byte array with sockets

          thx.

          "Jon Skeet [C# MVP]" wrote:
          [color=blue]
          > TomHL <TomHL@discussi ons.microsoft.c om> wrote:[color=green]
          > > Hi Jon, thx for your answer.
          > > How do I cretae and send the Header with the byte array (don't forget that I
          > > need to send it attached to the byte array :-))?[/color]
          >
          > You don't need to send it "attached" to the byte array. Just send the
          > header (as a byte array), then send the byte array itself. Don't forget
          > it's just a stream of data when all is said and done.
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
          > If replying to the group, please do not mail me too
          >[/color]

          Comment

          Working...