Let's talk about some tips and tricks that you can use while making an application.
Using JSON:
The JSON format is an easily readable format in JavaScript. It is always good to transfer data in the JSON format.
Object-based structure for WebSockets:
Normally, in any application where we have to transfer different data sets, it is always preferred that we finalize a proper structure for the messages. Take the example of a chatting application: if we finalize a structure, it is better to handle the message. Here is a sample structure:
{ type: "message" data : { from: "varun" to : "user1" data : "hello" } }
Using ArrayBuffer:
There is another way to send data using ArrayBuffer; you can also send a Binary Large Object (BLOB). Here is an example of the same:
var array = new Float32Array(5); for(var i = 0; i < array.length; ++i) { array[i] = i / 2; } ws.send(array, { binary: true, mask: true });
These kinds of structures can help in...