简体   繁体   中英

In C, how to periodically send UDP datagram to multiple peers (possibly thousands)?

(I'm new to network programming, and I am working on C in Linux) I followed Beej's guide for a simple UDP listener-talker and I know how to create a socket and send that to a destination (with calls to getaddrinfo() and socket() using SOCK_DGRAM) See http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#datagram .

In my distributed app, I will need to send a message to multiple peers (reliable multicast). My question is: do I need to create a socket for each of the peers? I'm worried about scalability. Or should I create the socket, use it and destroy it (close it) after each message?

In summary, is there a good way to send a UDP packet to multiple destinations, periodically? Thanks for the help!

For UDP, you need but one local socket. You can send a packet to any destination you like from that one, single socket.

Also, you don't need to destroy and recreate the socket after each message. Just keep the socket open, and keep sending messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM