erlang gen_tcp的正确使用方法:使用IPv6地址连接

lrpiutwd  于 2022-12-08  发布在  Erlang
关注(0)|答案(3)|浏览(156)

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.

r6vfmomb

r6vfmomb1#

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
hmmo2u0o

hmmo2u0o2#

根据gen_tcp模块的手册页,connect/3-4的第一个参数应该是inet:socket_address()inet:hostname()类型。
尝试使用This形式的类型。

s4n0splo

s4n0splo3#

除了(0,0,0,0,0,0,0,0,1}。我们也可以使用您自己的IPv6地址。请使用inet:parse_address(“您的IP地址”)。

相关问题