I intend to stream 100x MB
or GB
of data to a WebSocket server by JS clients. Like this post:
But my server is in Go rather than JS. I mean there is a Go WebSocket server implemented by https://github.com/gorilla/websocket
One option suggested is to use BinaryJS:
BinaryJS: both server and client are JS
var BinaryServer = require('../../').BinaryServer;
// Start Binary.js server
var server = BinaryServer({port: 9000});
<script src="http://cdn.binaryjs.com/0/binary.js"></script>
<script>
// Connect to Binary.js server
var client = new BinaryClient('ws://localhost:9000');
Is it possible to use BinaryJS along with a Go server? Is any equivalent Go package?
For data of Float32Array
type above 200 MB
in size to be sent from JS to a Go WebSocket server, there is no need for streaming at all, tests show.
Just make sure ws.binaryType = 'arraybuffer';
is used before ws.send(positions);
.
var positions = attrPos.array;
function connect() {
return new Promise(function(resolve, reject) {
var ws = new WebSocket('ws://127.0.0.1:8081/echo');
ws.onopen = function() {
resolve(ws);
};
ws.onerror = function(err) {
reject(err);
};
ws.onclose = function(evt) {
console.log("CLOSE SOCKET", new Date().toLocaleString());
};
ws.onmessage = function(evt) {
console.log("RESPONSE SOCKET: " + "RECEIVED" /* evt.data */, new Date().toLocaleString());
};
});
}
connect().then(function(ws) {
// onopen
console.log("OPENED SOCKET", new Date().toLocaleString());
console.log("SEND: START", new Date().toLocaleString());
ws.binaryType = 'arraybuffer'; // ** Critical statement
ws.send(positions);
ws.close();
}).catch(function(err) {
// onerror
console.log("ERROR: " + evt.data, new Date().toLocaleString());
});