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 be recv(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 where recvfrom(2) is usefull - it gives you the address of the client.


这篇关于Send same packets to multiple clients的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程