Last active
August 29, 2015 14:19
-
-
Save searler/99b294e43a616fdb3014 to your computer and use it in GitHub Desktop.
Create RxJava Observable from Socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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