In my Android app I need to use a Socket
to send and receive arrays of bytes. For convenience sake I want to work with Observable
connected to a Socket
.
Looking on the internet I've found this code:
import rx.lang.scala.Observable
val s = Observable.using[Char,Socket](new Socket("10.0.2.2", 9002))(
socket => Observable.from[Char](Source.fromInputStream(socket.getInputStream).toIterable),
socket => Try(socket.close))
.subscribeOn(rx.lang.scala.schedulers.IOScheduler.apply)
val a = s.subscribe(println, println)
It works but outputs one character at a time, for example when sent a "hello there" string, the output is:
I/System.out: h
I/System.out: e
I/System.out: l
I/System.out: l
I/System.out: o
I/System.out:
I/System.out: t
I/System.out: h
I/System.out: e
I/System.out: r
I/System.out: e
But I want to receive a buffered arrays of bytes in my subscription. How can I achieve that?