Skip to content

Instantly share code, notes, and snippets.

@searler
Last active August 29, 2015 14:19
Show Gist options
  • Save searler/99b294e43a616fdb3014 to your computer and use it in GitHub Desktop.
Save searler/99b294e43a616fdb3014 to your computer and use it in GitHub Desktop.
Create RxJava Observable from Socket
import rx.lang.scala._
import java.net.Socket
import scala.util.Try
import scala.io.Source
object SocketReactive extends App {
val s= Observable.using[Char,Socket](new Socket("localhost",1234))(
socket => Observable.from[Char](Source.fromInputStream(socket.getInputStream).toIterable),
socket=>Try{socket.close})
s.foreach{print}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment