0

My application requires a section for users to communicate each other. For this, I am using socket-io. For sending text(as strings). I use utf-8, which works perfectly.

However, when sending an image or a video on a socket, how do I approach this? Would I turn the image or the video into binary format, and send that on the socket?

1 Answer 1

1

Yes there is an example about how to send your files with socket.io :

var fileReader = new FileReader(), slice = file.slice(0, 100000); fileReader.readAsArrayBuffer(slice); fileReader.onload = (evt) => { var arrayBuffer = fileReader.result; socket.emit('slice upload', { name: file.name, type: file.type, size: file.size, data: arrayBuffer }); } 

there is a full tutorial with example about send file with socket.io and receive it in the server nodeJs follow this

Sign up to request clarification or add additional context in comments.

7 Comments

Yes bro it is a peer to peer
Is there another way for a peer-peer application, something more simpler?
@EesaMunir Yes there is you can use webRTC there is a framework who help you in your project peerjs ... good luck
Thank you man. So does webRTC do all the binary reading and opening for you?
@EesaMunir yes it do, but if you want save the chat history i recommend that u do it with webSocket because when users send message it will be manipulating and saved on the Server(DataBase)... Good luck :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.