socketIO-client icon indicating copy to clipboard operation
socketIO-client copied to clipboard

add binary support

Open wwqgtxx opened this issue 9 years ago • 14 comments

to fix issue #130

wwqgtxx avatar Jan 01 '17 17:01 wwqgtxx

@wwqgtxx i hope this PR will be merged soon but its better if you can edit the Readme file for showing the way to emit with binary data?

If i have image from camera and i want to emit, what should i do? transform it to byte and send?

khanhvu161188 avatar Jan 05 '17 16:01 khanhvu161188

It would be great to get this merged and the fix in issue https://github.com/invisibleroads/socketIO-client/pull/126

Joe-Palmer avatar Jan 05 '17 17:01 Joe-Palmer

@khanhvu161188 It's only need to send data with the python's bytearray type by emit() or send() And if server return a binary data, the client will still return a bytearray data to you, then to can do some things you wants to do. In my opinion,I wants to use the bytes type directly, but it will cause some problem to compatible between python 2 and 3, use bytearray can distinguish the different with binary data or text data easily.

Notice: This patch can't let the binary data send on the XHR protocol now, please check the connect protocol is websocket and then send the bytearray binay data.

wwqgtxx avatar Jan 06 '17 03:01 wwqgtxx

@wwqgtxx Since @invisibleroads didn't merge our MR, can u give me some tips for cloning your project, compiling it and use instead of version that I install via pip. Thanks in advance!

khanhvu161188 avatar Jan 12 '17 03:01 khanhvu161188

@khanhvu161188 you can try to use

pip install https://github.com/wwqgtxx/socketIO-client.git

wwqgtxx avatar Jan 12 '17 03:01 wwqgtxx

@wwqgtxx tks so much.

Notice: This patch can't let the binary data send on the XHR protocol now, please check the connect protocol is Websocket and then send the bytearray binay data Can we force setup for only connecting via websocket instead of xhr?

khanhvu161188 avatar Jan 12 '17 03:01 khanhvu161188

@wwqgtxx I'm trying to use openCV for reading frame and then try to send via socket.io

http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html

cvEncodeImage returns single-row matrix of type CV_8UC1 that contains encoded image as array of bytes.

So can i use this result for sending via socket.io ? Its bytearray

Also when i receive from client, can you give me some detail for transform this bytearray to image

khanhvu161188 avatar Jan 17 '17 23:01 khanhvu161188

the simple way to confirm you send a bytearray is

sio.send(bytearray(your_data))

If this code not cause error, it well send the binary data to server successfully.

wwqgtxx avatar Jan 17 '17 23:01 wwqgtxx

@wwqgtxx I can see data come to server and other client can receive it. So now how can i render it on web browser? it is png image

khanhvu161188 avatar Jan 17 '17 23:01 khanhvu161188

@wwqgtxx i got the answer. For getting image from bytearray that send via socket.io , we can do it

socket.on('client_receive_videodata', function (utiId,data) {
      console.log("receiving live video data....");
      var blob = new Blob([data], { type: 'image/jpeg' });
      var objectUrl = URL.createObjectURL(blob); 
      $("#photo").attr("src",objectUrl);
    });
    

Hope its helpful for another

khanhvu161188 avatar Jan 18 '17 00:01 khanhvu161188

@wwqgtxx Thank you for submitting a pull request that focuses on binary support. A lot of people want this! I'll work on merging this and @feus4177's work by March 1st.

I might be able to get to it before if I can find three solid days to focus on socket.io stuff. At any rate, it looks like it's work that must be done sooner or later.

invisibleroads avatar Jan 23 '17 22:01 invisibleroads

@invisibleroads is there any update on the progress of merging the binary support in by march 1st? It would be awesome to be able to go back to this main repo and not be porting fixes to feus' version too from here! If there's anything I can do to help you let me know :)

wilsonge avatar Feb 21 '17 18:02 wilsonge

@invisibleroads Hi ! Same here binary support would be awesome !

Thanks for all your work ! And thanks @wwqgtxx for your PR.

AMontagu avatar May 04 '17 10:05 AMontagu

Would be great to have this available.

Trying this PR and the other fork I see some issues when sending bytes data on websockets that are also transmitting strings (JSON) with separate frames getting jumbled together.

edit: Scratch that, I was communicating with a py27 server. Everything works great.

mfitzp avatar Jul 27 '17 18:07 mfitzp