开发者

Sending packets via UDP in erlang

开发者 https://www.devze.com 2023-03-03 08:25 出处:网络
so i\'m trying to send udp packet to a listening port on a computer which is not connecte开发者_开发问答d to the same LAN but has internet access via gen_udp in erlang.

so i'm trying to send udp packet to a listening port on a computer which is not connecte开发者_开发问答d to the same LAN but has internet access via gen_udp in erlang.

I start my first node by opening the port ({ok, Socket} = gen_udp:open(8887).) and the open the port on the other node the same way, When i send a packet from one node to the other via gen_udp:send i don't receive anything (trying flush() on the receiving node), So i'm wondering if there is something i'm doing wrong ? , i checked the firewalls and erlang and epmd is permitted.


did you try setting the controlling process of the Socket as the current process via : gen_udp:controlling_process(Socket,Pid) ?

You should then setup a receive loop and messages will be sent to you. The format of the messages should be : {udp, Socket, IP, InPortNo, Packet}

You could also try setting the socket to passive mode by using inet:setopts(Socket, [{active, false}]) after you have opened it. After which you can use 'gen_udp:recv/3` to read from the socket.

0

精彩评论

暂无评论...
验证码 换一张
取 消