You can send three things over a websocket (from the client perspective):
- Strings
- ArrayBuffers
- Blobs
If you have a compound Javascript data structures (hierarchy of maps and arrays) then you should use JSON to serialize them to strings and send them over the WebSocket connection as a string.
If you are interested in sending binary byte or file data over the WebSocket connection you could still serialize to a string (inefficient bandwidth-wise) or you can send the data as ArrayBuffers or Blobs.
Note 1: When sending an ArrayBuffer or Blob results in a binary WebSocket frame on the wire your server needs to support binary frames.
Note 2: The client gets to choose what type of object is returned when the server sends a binary frame. This is the binaryType property on the WebSocket object which can be set to either "arraybuffer" or "blob".
Note 3: If you browser only supports the older WebSocket Hixie protocol series (e.g. iOS Safari) then there is no binary data and you can only send and receive strings.