Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » WebSockets client in javascript connected to an U++ server sending binary messages
WebSockets client in javascript connected to an U++ server sending binary messages [message #50418] Thu, 25 October 2018 08:40 Go to next message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
Veteran
I want to send binary messages from a WebSockets server in U++ to a Javascript client.
When handling onmessage(), it seems U++ sends a Blob type. However I cannot get the data of that Blob.
Could you submit an example of getting binary data in Javascript sent from an U++ WebSockets server?
Thank you!


Best regards
Iñaki

[Updated on: Thu, 25 October 2018 08:41]

Report message to a moderator

[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 Go to previous message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
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
Previous Topic: Web page in U++ under IIS
Next Topic: SSH package for U++
Goto Forum:
  


Current Time: Sat Feb 23 20:38:17 CET 2019

Total time taken to generate the page: 0.00527 seconds