Różnice między wybraną wersją a wersją aktualną.
| Both sides previous revision Poprzednia wersja Nowa wersja | Poprzednia wersja | ||
| 
                    sk2:multicast_example [2016/11/22 09:38] jkonczak  | 
                
                    sk2:multicast_example [2021/12/20 13:49] (aktualna) jkonczak  | 
            ||
|---|---|---|---|
| Linia 1: | Linia 1: | ||
| ==== Przykład użycia UDP multicast ==== | ==== Przykład użycia UDP multicast ==== | ||
| - | <code cpp multicast_example> | + | <code cpp multicast_example.cpp> | 
| + | #include <cstdlib> | ||
| #include <cstdio> | #include <cstdio> | ||
| #include <csignal> | #include <csignal> | ||
| Linia 30: | Linia 31: | ||
| * setsockopt of IP_ADD_MEMBERSHIP sends an IGMP message "join group" and tells OS that the program waits for messages for the group. | * setsockopt of IP_ADD_MEMBERSHIP sends an IGMP message "join group" and tells OS that the program waits for messages for the group. | ||
| *  | *  | ||
| - | * More info at: http://www.tldp.org/HOWTO/text/Multicast-HOWTO | + | * More info at: https://tldp.org/HOWTO/Multicast-HOWTO-6.html | 
| */ | */ | ||
| Linia 54: | Linia 55: | ||
| // create socket | // create socket | ||
| int sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); | int sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); | ||
| - | if(sockfd==-1) error(1,errno, "sendto"); | + | if(sockfd==-1) error(1,errno, "socket"); | 
| // set SO_REUSEADDR (or only one app will be allowed to receive multicast messages from the groupIP:port pair) | // set SO_REUSEADDR (or only one app will be allowed to receive multicast messages from the groupIP:port pair) | ||
| Linia 115: | Linia 116: | ||
| // close socket AND interrupt all blocked recvfrom  | // close socket AND interrupt all blocked recvfrom  | ||
| shutdown(sockfd, SHUT_RDWR); | shutdown(sockfd, SHUT_RDWR); | ||
| + | close(sockfd); | ||
| // wait for child | // wait for child | ||
| readerThread.join(); | readerThread.join(); | ||