Home » U++ Library support » U++ MT-multithreading and servers » WebSockets client in javascript connected to an U++ server sending binary messages
|
[SOLVED] Re: WebSockets client in javascript connected to an U++ server sending binary messages [message #50419 is a reply to message #50418] |
Thu, 25 October 2018 09:14 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior Veteran |
|
|
This works!
From U++ server:
double data[] = {1, 2, 3, 4};
ws.SendBinary(String((char *)data, sizeof(data)));
From Javascript client:
ws = new WebSocket("ws://localhost:80");
ws.onmessage = function (evt) {
if (evt.data instanceof ArrayBuffer)
// Nothing here
else if (evt.data instanceof Blob) {
var reader = new FileReader();
reader.onload = function (e) { // Async read
if (e.target.result instanceof ArrayBuffer) {
var data = new Float64Array(e.target.result);
var len = data.length; // Read 4
var num1 = data[0]; // Read 1
var num2 = data[1]; // Read 2
var num3 = data[2]; // Read 3
var num4 = data[3]; // Read 4
} else
// Nothing here
};
reader.readAsArrayBuffer(evt.data);
} else if (typeof evt.data === "string") {
// Read text data
Best regards
Iñaki
|
|
|
Goto Forum:
Current Time: Fri Sep 20 10:41:13 CEST 2024
Total time taken to generate the page: 0.05441 seconds
|