Correct way of using gen_tcp:connect with IPv6 Address

651 Views Asked by At

Does anyone know how to connect to ipv6 tcp server address. Following tried but does not work.

{ok, Socket} = gen_tcp:connect("2a01:488:67:1000:253d:cd31:0:1", 5000, [{active, false},inet6]).
{error,enetunreach}

And this

{ok, Socket} = gen_tcp:connect("[2a01:488:67:1000:253d:cd31:0:1]", 5000, [{active, false},inet6]).
{error,nxdomain}

The server is reachable over IPv4 though.

Thanks.

3

There are 3 best solutions below

0
Pouriya On

According to the manual page of gen_tcp module, First argument of connect/3-4 should be type of inet:socket_address() or inet:hostname().
Try using This form of type.

0
Kushal Kothari On

On shell A:

$erl

{ok, LSocket} = gen_tcp:listen(12345, [binary, {packet, line}, {active, true}, {reuseaddr, true}, inet6, {ip, {0,0,0,0,0,0,0,1}}]).

to test, on shell B:

$telnet ::1 12345
0
Kushal Kothari On

Instead of (0,0,0,0,0,0,0,1}.We can also use your own IPv6 address. Use inet:parse_address("your IP address").