Refering to the documentation Working with Streams I have a question:
How can I implement a TCP service which is just sending data when there is a new connection.
In my case I just want to send data continuously from another Source when a client connects.
But from my understanding a Flow[ByteString] requires receiving something first.
I’m probably wrong, but I cant figure out how to achieve just sending data.
Tcp.IncomingConnection doesn’t have a write method or something similar.
A TCP connection is indeed handled with a Flow. A Flow basically is just something that receives and produces data. In most cases like in the example, it transforms incoming data and produces outgoing data from that. But that’s not the only way a flow can be built. You can also create a Flow where receiving incoming data and producing outgoing data is completely independent. You can use Flow.fromSinkAndSource to achieve that. If you are not interested in receiving any data all, you can use a Sink.ignore for the receiving side and provide whatever you like for the Source side.
val outgoingDataSource = ...
val sendFlow = Flow.fromSinkAndSource(Sink.ignore, outgoingDataSource)