Sending additional info with byte array with sockets

G

Guest

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.
 
J

Jon Skeet [C# MVP]

TomHL said:
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.

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.
 
G

Guest

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 :))?
 
J

Jon Skeet [C# MVP]

TomHL said:
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 :))?

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.
 
G

Guest

thx.

Jon Skeet said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top