Allow single connection with Akka stream as tcp server
|Added at||2016-12-26 14:12|
I am trying to build a simple tcp server using Akka streams.
I want to allow maximum one connection at a time. To achieve this I have added the following line into my
With this configuration, akka allows only one connection at a time. However, as soon as the second connection is attempted it rejects the request and fails itself with the following message:
From this point, it is not possible to establish any connection since the Tcp server is down.
Question: What is the proper way of enabling only one connection at a time? The main purpose is answering the first connection request and rejecting others while it is still in progress. It should be again possible to make another connection, after the previous connection is closed. As I mentioned, only one connection should be allowed at any time.
BONUS: Is it possible to provide a whitelist to make akka stream accept connections only from this list? I am planning to allow only known ip addresses to connect my server. To achieve this, I think it is enough to know the proper way of rejecting a request. So I can compare the incoming connection's ip address with a given list and reject if it is not in there. But any better solution is also appreciated.