Currently you can only transfer raw text data over websockets, but isn’t it wasteful to transfer numbers over like this?
I read some applications use base64 encoding, but I also remember that adds quite a lot of overhead to your data.
So my questions:
- Is it better to use yEncoding over base64?
- Should I bother with either of them for regular numbers?
Do not optimize prematurely. Unless you are transferring a LOT of numbers (i.e. many MB per second), just send your numbers as strings. Doing a special encoding will save you bandwidth at the cost of CPU (on both ends).
In noVNC I use base64 to be able to transfer binary data over WebSockets. This increases the bandwidth over raw binary by 33% (unfortunately, necessary until the API exposes a binary interface), but I still get good performance and I am transferring many MB per second. So the moral is, don’t optimize until you have a good reason to do so. Go with the simple straight-forward and well designed solution first and then optimize when you have a real reason to do so.