是否可以将来自不同进程的数据多播到同一主机和端口? [英] Is it okay to multicast data from different processes to the same host and port?

查看:71
本文介绍了是否可以将来自不同进程的数据多播到同一主机和端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个进程将不同类型的消息发送到同一ip和端口,因此在编写客户端时,我只需要一个读取器线程,而不需要多个读取器线程.我是否已开始采用设计模式,还是我的策略不建议使用?显然,我可以发送到不同的ip:port,但这将意味着客户端上有多个线程.有什么想法吗?

I have multiple processes sending different types of messages to the same ip and port so that when I write the client I would only need one reader thread rather than multiple reader threads. Have I embarked on a design pattern or is my strategy ill advised? Obviously, I could send to different ip:port but that would mean multiple threads on my client. Any thoughts?

推荐答案

您将多播数据发送到和端口,而不是主机".侦听进程必须加入该组,发送进程必须启用IP_MULTICAST_LOOP套接字选项.看看这个基于TCP/IP HOWTO的多播.

You send multicast data to a group and port, not to "host". Listening processes would have to join that group, and sending process will have to enable IP_MULTICAST_LOOP socket option. Take a look at this Multicast over TCP/IP HOWTO.

免责声明:我不确定,但是我相信该套接字选项的含义在Windows上是相反的,因此,如果不幸的话,请检查MSDN或其他内容.

Disclaimer: I don't know for sure, but I believe that the meaning of that socket option is reversed on Windows, so if you are that unlucky - check the MSDN or something.

多个进程将数据发送到同一UDP端口是完全可以的,因为接收方的粒度是每次读取一个数据报,并且您知道每个数据报的发送位置(请参见 recvfrom(2) ).

It's totally OK for multiple processes to send data to the same UDP port since granularity on the receiver side is one datagram per read, and you know where each datagram was sent from (see recvfrom(2)).

这篇关于是否可以将来自不同进程的数据多播到同一主机和端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆