简体   繁体   English

通过erlang中的UDP发送数据包

[英]Sending packets via UDP in erlang

so i'm trying to send udp packet to a listening port on a computer which is not connected to the same LAN but has internet access via gen_udp in erlang. 因此,我试图将udp数据包发送到未连接到同一LAN的计算机上的侦听端口,但可以通过erlang的gen_udp进行互联网访问。

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 ? 我通过打开端口( {ok, Socket} = gen_udp:open(8887). )来启动我的第一个节点,并以相同的方式打开另一个节点上的端口,当我通过gen_udp:send从一个节点向另一个节点发送数据包时gen_udp:send我什么都没收到(在接收节点上尝试flush()),所以我想知道是否我做错了什么? , i checked the firewalls and erlang and epmd is permitted. ,我检查了防火墙,并允许使用erlang和epmd。

did you try setting the controlling process of the Socket as the current process via : gen_udp:controlling_process(Socket,Pid) ? 您是否尝试通过gen_udp:controlling_process(Socket,Pid)将Socket的控制进程设置为当前进程?

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} 消息的格式应为: {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. 打开套接字后,您也可以尝试使用inet:setopts(Socket, [{active, false}])将套接字设置为被动模式。 After which you can use 'gen_udp:recv/3` to read from the socket. 之后,您可以使用'gen_udp:recv / 3`读取套接字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM