Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Javascript sending an Image through ofxLibwebsockets

$
0
0

@leefeel wrote:

I'm sending a snapshot of my webcam, to my openframeworks server, using websockets:

	    var ws = new WebSocket("ws://192.168.1.130:9093");
    	ws.binaryType = "arraybuffer";

    var ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0);

    	var image = canvas.toDataURL("image/jpeg");
    	ws.send(image);

But on the server, using the "example_server_blob" from ofxLibwebsockets. The image doesn't arrive on args.data, it arrives on args.message:

void ofApp::onMessage(ofxLibwebsockets::Event& args) {
    ...
   	if (args.isBinary) {

isBinary is false. args.data.size() is 0. The jpeg image, is placed in args.message, I don't know why. But even if I try to assign the information from message to the buffer:

buff.clear();
buff.set(args.message);

locked = true;
needToLoad = true;

I have an error on turboJpeg:

Error in tjDecompressHeader2():
Not a JPEG file: starts with 0x64 0x61

I tried at onMessage, to return back the same message to the client:

args.conn.send(args.message);

And I assigned to an image on the page. And It works properly, so It looks like the information sent is correct:

ws.onmessage = function(e) {
		console.log("Receiving message");
		document.getElementById("streamed").src = e.data;
	}

So, right now the problem is why the image is arriving on the message attribute of the event.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles