Send same packets to multiple clients
2022/4/6 23:25:52
本文主要是介绍Send same packets to multiple clients,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
https://stackoverflow.com/questions/4883689/send-same-packets-to-multiple-clients
question:
I have to develop a software to send same packets to multiple destination. But i must not use multicast scheme.!!!! ( because my boss is a stupid man ) so, any way, the problem is that: i have same packets and multiple IP address ( clients) and i can not use multicast how can i do that in the best way? i must use c++ as a language and Linux as a platform. so please help me
answer:
This could be done with either TCP or UDP depending on your reliability requirements. Can you tolerate lost or reordered packets? Are you prepared to handle timeouts and retransmission? If both answers are "yes", pick UDP. Otherwise stay with TCP. Then:
- TCP case. Instead of single multicast UDP socket you would have a number of TCP sockets, one per destination. You will have to figure out the best scheme for connection establishment. Regular listening and accepting connecting clients works as usual. Then you just iterate over connected sockets and send your data to each one.
- UDP case. This could be done with single UDP socket on the server side. If you know the IPs and ports of the clients (data receivers) use
sendto(2)
on the same data for each address/port. The clients would have to berecv(2)
-ing at that time. If you don't know your clients upfront you'd need to devise a scheme for clients to request the data, or just register with the server. That's whererecvfrom(2)
is usefull - it gives you the address of the client.
这篇关于Send same packets to multiple clients的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23增量更新怎么做?-icode9专业技术文章分享
- 2024-11-23压缩包加密方案有哪些?-icode9专业技术文章分享
- 2024-11-23用shell怎么写一个开机时自动同步远程仓库的代码?-icode9专业技术文章分享
- 2024-11-23webman可以同步自己的仓库吗?-icode9专业技术文章分享
- 2024-11-23在 Webman 中怎么判断是否有某命令进程正在运行?-icode9专业技术文章分享
- 2024-11-23如何重置new Swiper?-icode9专业技术文章分享
- 2024-11-23oss直传有什么好处?-icode9专业技术文章分享
- 2024-11-23如何将oss直传封装成一个组件在其他页面调用时都可以使用?-icode9专业技术文章分享
- 2024-11-23怎么使用laravel 11在代码里获取路由列表?-icode9专业技术文章分享
- 2024-11-22怎么实现ansible playbook 备份代码中命名包含时间戳功能?-icode9专业技术文章分享