1

This post to the question "What is base 64 encoding used for?" says:

When you have some binary data that you want to ship across a network, you generally don't do it by just streaming the bits and bytes over the wire in a raw format. Why? because some media are made for streaming text. You never know -- some protocols may interpret your binary data as control characters (like a modem), or your binary data could be screwed up because the underlying protocol might think that you've entered a special character combination (like how FTP translates line endings).

I've used sockets in Java a hundert times to send binary data over networks. And as far as I know it very common to send binary data over networks especially if you have big data. I don't see why some devices could interpret binary data wrong, since it contains TCP header etc.

SOAP MTOM also sends binary data over networks.

Am I misunderstanding something? I'm irritated, because this post has many upvotes and is accepted.

Community
  • 1
  • 1
Lars
  • 1,750
  • 2
  • 17
  • 26

1 Answers1

2

The answer you link to isn't incorrect, it just fails to explicitly mention some examples. The answer is in the quote as well:

because some media are made for streaming text

Sockets deal in bytes, they don't care what they transport. It is the higher-level protocols, or the message formats they transport, that do.

It's when this binary data is wrapped in envelopes of such protocols or formats that they can wreak havoc. A less than (<) character in image bytes is perfectly valid, but when used in an XML message, it will break the XML. Other characters, like control characters, can have an influence on how further data is to be interpreted by a protocol handler.

So base64 is used to wrap binary data in a safe-for-transport way where that would otherwise not be safe.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • I understand your answer, but the other answer sounds like base64 (or any other encoding) is always needed for binary data transfer. If you don't need your data in a readable format, like XML, it is also save to send the bits in the http protocol. – Lars May 11 '16 at 10:52
  • Well yeah you can interpret the answer like that, _"just base64 encode always to be sure"_, and then it's a silly answer, I agree. – CodeCaster May 11 '16 at 10:53