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.
标签:UDP,multiple,clients,packets,use,TCP,same 来源: https://www.cnblogs.com/ztguang/p/16108317.html