MultiCast到同一台机器上的多个客户端的消息 [英] MultiCast Messages to multiple clients on the same machine

查看:483
本文介绍了MultiCast到同一台机器上的多个客户端的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我试图写一个服务器/服务,在第二次或第二次广播一个消息, p>该消息需要由
多个客户端程序接收,在同一台机器或不同的
机器上可以是
。但是在同一时间在
上运行的每台机器可能会有
以上的一个程序。


delphi7,with indy 9.0.18



其中im卡住了,如果我应该使用UDP(TIdUDPClient / Server)或IP MultiCast(TIdIPMCastClient / Server),或者如果它甚至可能...



我设法让它与IP Multi Cast一起使用,每台机器有一个客户端,但即使在许多具有不同绑定的trys之后..最大/最小端口等我似乎找不到解决方案。

解决方案

我想你正在寻找 SO_REUSEADDR 套接字选项。在套接字上设置该选项允许多个套接字在同一端口上侦听。对于组播Windows,保证消息将被传递到所有套接字(否则消息只会随机发送到一个套接字)。



通常通过调用setsockopt来执行此操作,但是我不是Delphi开发人员,所以我不知道你的API是什么样子的。这个问题似乎显示了一个在Delphi中做类似事情的人的例子。


Im trying to write a server/service that broadcasts a message on the lan ever second or so, Kind of like a service discovery.

The message needs to be received by multiple client programs that could be on the same machine or different machines. But there could be more than one program on each machine running at the same time.

Im using delphi7, with indy 9.0.18

where im stuck is if i should be using UDP(TIdUDPClient/Server) or IP MultiCast (TIdIPMCastClient/Server) or if its even possible...

Ive managed to get it to work with IP Multi Cast with one client per machine, but even after many trys with different bindings.. max/min ports etc, i cant seem to find a solution.

解决方案

I think you're looking for the SO_REUSEADDR socket option. Setting that option on a socket allows multiple sockets to listen on the same port. For multicast Windows guarantees that the message will be delivered to all sockets (otherwise the message only goes to one socket, randomly).

You usually do this by calling setsockopt, but I'm not a Delphi developer so I'm not sure what your API looks like. This question seems to show an example of someone doing something similar in Delphi.

这篇关于MultiCast到同一台机器上的多个客户端的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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