JDare / ClankBundle

A Symfony2 Bundle for use with Ratchet WebSocket Server
MIT License
131 stars 31 forks source link

Binary data through websockets #41

Closed MaxenceWO closed 9 years ago

MaxenceWO commented 9 years ago

Hi,

I can't find how to send binary data from a client to a web server through ClankBundle websockets. Blobs seem corrupted. Do you have a clue about this problem ?

I use Filereader Api from the javascript client and readAsBinaryString method to get blobs from a file.

Thanks.

jjsaunier commented 9 years ago

Quick solution : $connection->send(new Frame($msg, true, Frame::OP_BINARY)); but this need to disable UTF-8 on server : $wsServer->setEncodingChecks(false);

look at ratchetphp/Ratchet#279

MaxenceWO commented 9 years ago

Thanks for your reply. Unfortunately, i can't get this to work. I don't have any problem about sending binary data from server to client but i still have a problem from client to server...

I'm using ClankBundle in a symfony2 project so it's a bit tricky to disable the encoding check (i have to go in vendors and modify the source code of the bundle). Even if with encoding check disabled, my data from the client is corrupted...

Do you have any clue about this problem ?

jjsaunier commented 9 years ago

Can you paste the part of code where you create the buffer array ?

MaxenceWO commented 9 years ago

Of course, thank you for your help. I use the FileApi to extract data from dropped files.

Get file :

var upload = new Uploader();

function drop(e){ var fr = new FileReader(); fr.readAsBinaryString(e.dataTransfer.files[0]); fr.onloadend = function(){ upload.setFp(this.result); }; }

the uploader : function Uploader(){ var session = null; var fp = null; this.setFp = function(v){ fp = v; }

var cl = Clank.connect("ws://xxxxxxxx:xx"); cl.on("socket/connect", function(sess){ session = sess; });

function send(){ session.publish("upload/uid/"+uid, {data: fp}); } }

I shortened my source code to clean up all unnecessary stuff.

MaxenceWO commented 9 years ago

Ok nevermind, i stopped using ClankBundle. There are way too many bugs (truncated data, high traffic closed my connection, etc). Anyway, thanks for you help.