简体   繁体   English

多播广播自我澄清

[英]Multicast Broadcasting to self clarification

Setup: 设定:

The user has two applications - one sender one receiver - running on the same host/server. 用户有两个应用程序-一个发送者一个接收者-在同一主机/服务器上运行。 The user sets it up such that the sender sends messages to its own IP address not 127.0.0.1. 用户对其进行设置,以便发件人将消息发送到其自己的IP地址而不是127.0.0.1。 Lets say its IP and port is x:y for simplicity. 为了简单起见,假设其IP和端口为x:y。 The user then sets up the receiver to receiver messages on x:y. 然后,用户将接收方设置为在x:y上接收消息。 Again this is on the same host/server. 同样,它在同一台主机/服务器上。

Questions: 问题:

  1. From my understanding this is not possible since the port will already be reserved. 据我了解,这是不可能的,因为该端口已经被保留。 Therefore I cannot use the same port to try and send packets out to myself. 因此,我不能使用相同的端口尝试向自己发送数据包。 Can I have a port used for a sender and receiver on the same node? 我可以在同一节点上使用用于发送方和接收方的端口吗?
  2. Is this resolved if I use SO_REUSEADDR or does this only resolve the IP conflict and not the port reuse? 如果我使用SO_REUSEADDR可以解决此问题,还是只能解决IP冲突而不解决端口重用问题?
  3. If the program is not setup with IP_MULTICAST_LOOP the host will not multicast the message to itself, correct? 如果未使用IP_MULTICAST_LOOP设置程序,则主机将不会向自身广播消息,对吗?
  4. With IP_MULITCAST_LOOP set, if I only wanted to send the message to myself can I use 127.0.0.1 or must I use another address? 设置IP_MULITCAST_LOOP后,如果我只想向自己发送消息,可以使用127.0.0.1,还是必须使用其他地址? Additionally, how do the ports get resolved? 此外,如何解决端口问题?
  5. If I am not seeing messages on the same node, would the first best guess be that IP_MULITCAST_LOOP is not set? 如果我没有在同一节点上看到消息,那么最好的猜测是未设置IP_MULITCAST_LOOP吗?

Let's take it step by step: 让我们逐步进行:

  1. The sending port does not matter at all. 发送端口根本没有关系。 So you can choose an arbitrary port for the sender, and use the specific port number for your service just for the receiver. 因此,您可以为发送方选择一个任意端口,并仅将特定端口号用于接收方的服务。

  2. No, SO_REUSEADDR/PORT does not solve this problem. 否,SO_REUSEADDR / PORT无法解决此问题。 Even if you manage to achieve it: Do not start multiple listeners on the same port. 即使您设法做到这一点:不要在同一端口上启动多个侦听器。 This will cause strange effects. 这会造成奇怪的影响。 The main purpose of SO_REUSEADDR/PORT is to allow servers to create a TCP (not UDP) socket when the previous server process just died, without waiting for a timeout of the TCP state machine of the stale socket. SO_REUSEADDR / PORT的主要目的是允许服务器在先前的服务器进程刚刚终止时创建TCP(而不是UDP)套接字,而无需等待过时套接字的TCP状态机超时。

  3. Corrects, assuming you mean multicast rather than broadcast , 更正,假设您的意思是组播而不是广播

  4. Yes and no: If you only want to send messages to yourself you can send the packets to 127.0.0.1, and then you message will be a normal unicast packet and no longer a multicast packet, and IP_MULTICAST_LOOP does not matter at all. 是和否:如果只想向自己发送消息,则可以将数据包发送到127.0.0.1,然后您的消息将是普通的单播数据包,而不再是多播数据包,并且IP_MULTICAST_LOOP完全无关紧要。 Multicast packets are normal UDP packets which have a destination address in the multicast address range (ie 224.0.0.0-239.255.255.255). 组播数据包是具有目的地址在组播地址范围内(即224.0.0.0-239.255.255.255)的普通UDP数据包。 The receiving socket cannot easily tell whether a packet was sent via unicast or multicast. 接收套接字无法轻松判断数据包是通过单播还是通过多播发送的。

  5. IP routing on the same host between interfaces is far from trivial. 接口之间同一主机上的IP路由绝非易事。 There are a lot of mechanisms and routing rules involved which are not shown in the normal routing table, which is just for outgoing traffic. 普通路由表中没有显示许多涉及的机制和路由规则,仅用于传出流量。 It also depends on by which means you try to observe the messages. 它还取决于您尝试观察消息的方式。 There is not a single point where you can see all messages going through a node (unfortunately). 没有一个地方可以看到所有消息通过一个节点(不幸的是)。 This is usually all attached to interfaces, and there also to an ingress and egress side, and the latter is usually not documented and not configurable. 通常,所有这些都附加到接口,并且还附加到入口和出口侧,并且入口和出口侧通常没有文档记录且不可配置。 Monitoring local traffic can be tricky and may require virtual network interfaces. 监视本地流量可能很棘手,可能需要虚拟网络接口。 Really messy. 真的很乱

In summary: You are trying to send messages from one process to another process on the same host. 总结:您正在尝试将消息从一个进程发送到同一主机上的另一个进程。 Use unicast UDP for this and you are done. 为此,使用单播UDP,就可以完成。 No multicast involved. 不涉及多播。

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

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