socket.io-client-java icon indicating copy to clipboard operation
socket.io-client-java copied to clipboard

send and receive stream in android

Open sys-samk opened this issue 12 years ago • 7 comments

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?

sys-samk avatar Aug 08 '14 09:08 sys-samk

how can i get image in android?

sys-samk avatar Aug 08 '14 09:08 sys-samk

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.

nkzawa avatar Aug 08 '14 16:08 nkzawa

Thanks for your replies.

sys-samk avatar Aug 08 '14 21:08 sys-samk

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?

addonajay avatar Jan 06 '16 15:01 addonajay

Its a late comment but its still open!. Get byte[] from the File object and try sending it over the socket?

bradley101 avatar Mar 13 '18 17:03 bradley101

@bradley101 is it possible to divide the large file in many part before sending one by one ?

maelfosso avatar Mar 24 '18 06:03 maelfosso

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

bradley101 avatar Mar 26 '18 07:03 bradley101