How to resolve "fly-global-services" into usable IP Address in Elixir

I am having problems with UDP packets reaching my application and tried to follow the guide here: Running Fly.io Apps On UDP and TCP · Fly Docs
How can I find out the IP Address of the special interface “fly-global-services” in Elixir/Erlang? It is not included in :inet.getifaddrs.
What am I doing wrong?

PS: There was a very recent post yesterday that covered a very similar topic. Unfortunately it was deleted, before I could read it again: Issues with elixir :gen_udp inbound connections

I found a very helpful snippet on Github: link

I was using the wrong function:

{:ok, {172, 19, 76, 91}} = :inet.getaddr(~c"fly-global-services", :inet)            
{:ok, sock} = :gen_udp.open(5000, [:binary, active: true, ip: {172, 19, 76, 91}])

Works fine and traffic comes through.

1 Like

To find the ip of fly-global-services this what I did.

def init(:ok) do
    {:ok, addr} = :inet.getaddr('fly-global-services', :inet)

    {:ok, socket} = :gen_udp.open(5000, [:binary, {:active, true}, {:ip, addr}])

    {:ok, socket}
 end

The other problem is that UDP doesn’t work with the share IPv4 not IPv6. I had to allocate an IPv4.

2 Likes

Thanks for the quick reply! I appreciate it
Good to note the allocated IPv4 address as well.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.