Please disregard previous message if you saw it, it was sent prematurely.
I am writing a websocket server that will stream real time data to multiple chromium javascript clients. I am trying to optimize the transfers so that I can send 380Kb in under 10ms. I am running all tests on my local machine. In short, between my server and a test C client I am able to get an average transfer rate of 7ms. On my chrome client it takes roughly 250ms. I'll explain my scenario and different tests in detail.
Server: I am using websocketpp as my main server and feeding up some binary data. The server sends 380kb of binary data whenever it receives a request message with text "FRAME". The server sets the opcode of the data to type BINARY. I tested this server using a simple client built with websocketpp. The client sends "FRAME", and then when receiving a complete message sends another "FRAME". This way I get complete frame after complete frame. I checked with the writer of websocketpp and at this time the message is not broken up into multiple segments, it is sent as one message.
JavaScript Client: I tried two clients. Both use websockets (obviously) but one does websocket communication in the main window while the other hands it off to a webworker. They both have comparable times so I will only show the test code for the main window. I tried receiving the data as an ArrayBuffer and as a Blob, with similar results.
thanks
var ws;
ws = new WebSocket(url);
ws.binaryType = "arraybuffer"; // or blob
ws.onopen = function(e) {
ws.send('FRAME');
};
ws.onerror = function(e) {
console.log(e);
};
ws.onclose = function(e) {
};
ws.onmessage = function(e) {
if (e.data instanceof ArrayBuffer) {
console.log("Got an arrayBuffer of size " + e.data.byteLength );
ws.send('FRAME');
} else if (e.data instanceof Blob) {
console.log("Got an arrayBuffer of size " + e.data.byteLength );
ws.send('FRAME');
} else {
console.log("message");
}
};