0

I'm use RxScala/Java construct a Observable to emit socket connection with a loop,the result is every connection as a event.Like this,

val server = new ServerEntrance("localhost", 10002)
val socket: Observable[ConnectedSocket] = server.listen

After that, connection able to start reading.I need subscribe the scoket connection event and make it as a new Observable.
ConnectedSocket can use stratReading,return Observable[CompletedProto],creating a Observable as connection do.It emit event with received information.I want to make this statement return Observable[CompletedProto].How to construct it?

socket.subscribe(l => l.startReading)

If need detail information I really willing update it.

LoranceChen
  • 2,453
  • 2
  • 22
  • 48
  • Have you looked at the `flatMap` or `flatMapLatest` operators? – Tamas Hegedus Mar 23 '16 at 16:19
  • @TamasHegedus, I have tried `flatMap` but if have multi subscriber the `startReading` will execute multi times.Caused `ReadPendingException` because `startReading` do a socket read operation multi times.I also confuse why Rx design map as this way.If you willing help me this question please [look here](https://github.com/ReactiveX/RxScala/issues/190). – LoranceChen Mar 24 '16 at 00:04
  • Observables are replayable by default (I think that is their weakness in some scenarios). If you want to convert it to a hot observable you could use `.publish()` with an immediate `.connect()`, or you can ensure at most one subscribers with `.singleInstance()` – Tamas Hegedus Mar 24 '16 at 08:49

0 Answers0