0
0

More than 5 years have passed since last update.

{error,eafnosupport}が出た時、erlang gen_udp:sendを使用する時の話

Posted at

結論

ipv4で通信する時はinet optionを使いましょう

問題

gen_udp:send/4を使う時{error,eafnosupport}が出た

Server Side

server.erl
    {ok, Socket} = gen_udp:open(9999,
                                [binary,
                                 inet6,
                                 ]).

Client Side

client.erl
   {ok, Socket} = gen_udp:open(0, [binary, inet6]).
   {ok,Addr} = inet:parse_address("10.12.**.**"). %% ipv4 address
   Ret = gen_udp:send(Socket, Addr, 9999, <<"hi">>).
   %%{error,eafnosupport}

解決

client.erl
   {ok, Socket} = gen_udp:open(0, [binary, inet]).
   {ok,Addr} = inet:parse_address("10.12.**.**"). %% ipv4 address
   Ret = gen_udp:send(Socket, Addr, 9999, <<"hi">>).
   %%ok.

わかったこと

ipv4でudp通信する時、サーバーサイトはinet6 optionにしてもipv4通信を受け入れられますが、クライアントサイトはちゃんとinet optionにしないとダメです

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0