Akka Streams: How to close a network connection

58 views
Skip to first unread message

Olaf Bergner

unread,
May 29, 2015, 1:12:42 PM5/29/15
to akka...@googlegroups.com
I'm currently experimenting with implementing a custom TCP protocol server. A requirement I have is being able to close a client connection under certain circumstances. The akka streams doc say

Closing connections is possible by cancelling the incoming connection Flow from your server logic (e.g. by connecting its downstream to an CancelledSink and its upstream to a completed Source). It is also possible to shut down the servers socket by cancelling the connections:Source[IncomingConnection].

However, I have been unable to figure out how to actually do this. Could someone please help out?

Best,
Olaf 
Message has been deleted

Olaf Bergner

unread,
May 31, 2015, 12:31:53 PM5/31/15
to akka...@googlegroups.com
I experimented a bit more and found two possible solutions:

conn.flow.concat(Source.empty).to(Sink.cancelled)

and

ctx.pushAndFinish(elem)

which both *seem* to do the same thing. Not sure whether I should prefer one over the other, though, or if there is a better way to do this.

Best,
Olaf
Reply all
Reply to author
Forward
0 new messages