简体   繁体   English

在所有(或几个)端口上监听Boost Asio UDP

[英]Boost Asio UDP listening on all (or several) ports

Is it possible to have a boost asio udp client that is listening for messages on several ports at the same time? 是否可能有一个boost asio udp客户端同时在多个端口上侦听消息? Or just listening for messages from any port? 还是只听来自任何端口的消息?

For background (and because I am new to networking and probably not picking the best way to do this), essentially my problem is I have a main node kicking off processes on several other nodes in a cluster. 对于背景(并且由于我不熟悉网络并且可能没有选择最佳方法),本质上我的问题是我有一个主节点启动集群中其他几个节点上的进程。 When each child node finishes its process, it is to send it's results to another node that is waiting for results. 当每个子节点完成其过程时,它将把其结果发送到另一个等待结果的节点。 I was thinking it would be easiest to simply do a UDP broadcast from each child node, with each child node broadcasting on a unique port, and the listener listening on all ports. 我认为,简单地从每个子节点进行UDP广播是最容易的,每个子节点都在唯一的端口上广播,而侦听器在所有端口上侦听。 Is there a better way to do this? 有一个更好的方法吗?

UDP sockets need to bind to a specific port if they have to receive incoming messages destined for that port. 如果UDP套接字必须接收发往该端口的传入消息,则它们需要绑定到特定端口。 If you want to listen on a multiple of ports, then you will have to open multiple UDP sockets and bind them to all those ports. 如果要侦听多个端口,则必须打开多个UDP套接字并将它们绑定到所有这些端口。 The bind method accepts the port number on which you wish to receive messages: http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/basic_datagram_socket/bind/overload1.html bind方法接受您希望在其上接收消息的端口号: http : //www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/basic_datagram_socket/bind/overload1.html

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

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