9

When binding calls to port 9000 with Akka-HTTP

Http().bindAndHandle(routes, "localhost", 9000)

It starts listening to the port as seen with 'netstat -tulpn'

Proto  Recv-Q  Send-Q  Local Address   Foreign Address  State   
tcp6   0       0       127.0.0.1:9000  :::*             LISTEN   

Locally this port can be used. However, when I make a remote call I get:

curl: (7) Failed to connect to 169.254.0.2 port 9000: Connection refused

Even though pinging is possible and the devices are directly connected. What am I doing wrong?

JasperJ
  • 1,192
  • 1
  • 12
  • 23

3 Answers3

23

Replace localhost with 0.0.0.0 and it will work. localhost is intended to be used only locally.

Pim Verkerk
  • 1,066
  • 7
  • 12
2

You need to bind to the IP address:

Http().bindAndHandle(routes, "169.254.0.2", 9000)
Pascal Soucy
  • 1,317
  • 7
  • 17
1

Listening only localhost interface is a good practice. In production use you should catch request from public interfaces via proxy (nginx or apache)

mgosk
  • 1,874
  • 14
  • 23