I have following code:
val serverSource = Http().bind("localhost", 8080)
val connectionSink = Sink.foreach[IncomingConnection] {
connection => println(s"Accepted incoming connection from ${connection.remoteAddress}")
}
val serverBindingFuture = serverSource.to(connectionSink).run()
serverBindingFuture.onComplete {
case Success(binding) => {
println("Server binding successful")
binding.terminate(10 seconds)
}
case Failure(ex) => println(s"Server binding failed $ex")
}
As the snippet tells, I am terminating the server binding after 10 seconds. So I expect that if I send the request before this period expires, I should get message 'Accepted incoming connection from...' printed.
But I observe that I always get 'This site can’t be reached', and message is never printed.