Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add binary support #144

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

add binary support #144

wants to merge 5 commits into from

Conversation

wwqgtxx
Copy link

@wwqgtxx wwqgtxx commented Jan 1, 2017

to fix issue #130

Signed-off-by: wwqgtxx <wwqgtxx@gmail.com>
Signed-off-by: wwqgtxx <wwqgtxx@gmail.com>
Signed-off-by: wwqgtxx <wwqgtxx@gmail.com>
Signed-off-by: wwqgtxx <wwqgtxx@gmail.com>
Signed-off-by: wwqgtxx <wwqgtxx@gmail.com>
@khanhvu161188
Copy link

@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?

@Joe-Palmer
Copy link

It would be great to get this merged and the fix in issue #126

@wwqgtxx
Copy link
Author

wwqgtxx commented Jan 6, 2017

@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 wwqgtxx changed the title add binary support from socketIO-client-2 add binary support Jan 6, 2017
@khanhvu161188
Copy link

@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!

@wwqgtxx
Copy link
Author

wwqgtxx commented Jan 12, 2017

@khanhvu161188 you can try to use

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

@khanhvu161188
Copy link

@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
Copy link

@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

@wwqgtxx
Copy link
Author

wwqgtxx commented Jan 17, 2017

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.

@khanhvu161188
Copy link

@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
Copy link

@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

@invisibleroads
Copy link
Owner

@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.

@wilsonge
Copy link

@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 :)

@AMontagu
Copy link

AMontagu commented May 4, 2017

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

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

@mfitzp
Copy link

mfitzp commented Jul 27, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants