Binary vs. String transfer over a stream

The WebSocket protocol (HyBi) supports two different payload types: text, binary. The text payload is UTF-8 encoded string data. Any ASCII codes above 127 in the string that you send will be converted into a two-byte UTF-8 encoding. To successfully send/receive raw binary data you will probably want to encode the data in something like base64 (which is UTF-8 compatible).

The binary payload type is sent directly. The bytes are sent as-is in the payload. This is more bandwidth efficient. It is means that you don't have to do an encode/decode step. The bytes you send get sent directly, and the bytes you receive can be accessed directly with no decoding.


When you are using binary mode there is no UTF-8 conversion of the data before sending it. As far as speed, there is very little difference as UTF-8 encoding of text is very fast and negligible. It looks like they give you two options so you can send that data either way depending on what data type you want to send.