Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do they tell apart different parts on a stream of bits

When data is transferred through a network it is obviously in binary form.

So it could be a number

1011001

and then some other data, maybe

1110100111001 

That are sent together.

How can we tell them apart when they arrive. Is there some special flag that indicates the end of each data?

If yes how do we make sure that it is unique and we don't get confused?

like image 574
ealiaj Avatar asked Dec 22 '25 08:12

ealiaj


1 Answers

You could define a special bitstring pattern as the beginning or end of a stream and some protocols do this, but you would have to make it either long enough (256-bit for example) that it is highly unlikely that it appears in the normal data stream.

A more reliable way would be to escape the ending pattern if it appears in the normal data. You probably know how that works, because everybody came into contact of using \ in strings at some point in time. They have to be escaped as \\.

A third way is applicable if you know in advance how long your stream will be, so you can send a length before actually sending the data.

The actual details are defined as the protocol and both sides must follow the structure of the protocol however it was defined.

like image 184
Artjom B. Avatar answered Dec 24 '25 10:12

Artjom B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!