View Source VintageNet.Connectivity.TCPPing (vintage_net v0.12.0)

Test connectivity by making a connection using TCP

Connectivity with a remote host can be checked by making a TCP connection to it. The connection either works, the connection is refused, or it times out. The first two cases indicate connectivity.

Normally ICMP is used for testing connectivity, but that requires the new socket API and a Linux kernel with net.ipv4.ping_group_range enabled. This way usually works unless a device is behind a strict firewall, but there's usually at least one IP address/port on the Internet that they allow.

Link to this section Summary


Check connectivity with another device

Link to this section Types

@type ping_error_reason() :: :if_not_found | :no_ipv4_address | :inet.posix()

Link to this section Functions

@spec ping(
  {VintageNet.any_ip_address(), non_neg_integer()}
) :: :ok | {:error, ping_error_reason()}

Check connectivity with another device

The "ping" is really a TCP connection attempt from the specified interface to an IP address and port. Failures to connect don't necessarily mean that the Internet is down, but it's likely especially if the server that's specified in the configuration is highly available.

Source IP-based routing is required for the TCP connect to go out the right network interface. This is configured by default when using VintageNet.