user3404572
user3404572

Reputation: 167

Correct way of using gen_tcp:connect with IPv6 Address

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.

Upvotes: 0

Views: 711

Answers (3)

Kushal Kothari
Kushal Kothari

Reputation: 11

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").

Upvotes: 0

Kushal Kothari
Kushal Kothari

Reputation: 11

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

Upvotes: 1

Pouriya
Pouriya

Reputation: 1626

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.

Upvotes: 0

Related Questions