send and receive stream in android
Hi my client is android.and i want to send image to server and vice versa. do i need to use socket.io-stream library in server side?
how can i get image in android?
socket.io-stream has no client for Java/Android.
If you just want to send/receive small images, do that as byte array:
// sending
byte[] img = data.toByteArray();
socket.emit("img", img);
// receiving
socket.on("img", new Emitter.Listener() {
@Override
public void call(Object... args) {
byte[] img = (byte[])args[0];
}
});
But be aware of that all binary data would be buffered to memory, so you can't handle big data.
Thanks for your replies.
Can i send any object? Lets say, if i want to pass any file then i just need to pass file object same as we are passing FileBody in MultiPartEntity in android.
File fileObj = new File(path);
socket.emit("file", fileObj);
socket.on("file", new Emitter.Listener() {
@Override
public void call(Object... args) {
File recFile = (File) args[0];
}
});
First of all is it possible?
Its a late comment but its still open!. Get byte[] from the File object and try sending it over the socket?
@bradley101 is it possible to divide the large file in many part before sending one by one ?
@maelfosso Yes! Specifically for that purpose I made a java library for that Differentiate Comment for any help in that :+1:
Add this to your gradle script (any Java project including Android)
compile 'com.bradley101.differentiate:differentiate:1.4'