How can i manage to join a multicast mpeg stream group with an address of udp://@224.1.50.15:1234
? What i want to manage is just to make a connection with the stream server to make the server become aware of that i am interested in this multicast group to make the server to send me the stream packets for a period of a time.
For an example: I am not receiving any packets from this multicast group until i establish a connection to the group with VLC Player. Even after i close the VLC Player i keep receiving packets from the group for a short period of time. What i am trying to do is to receive the packets without the help of VLC Player or any other third party application.
How can i manage to make a connection with this group for the purpose above. If it is even possible?
P.S: I have 4 network interfaces installed.
Thank you!
As the recommendation of Zaboj Campula in his answer in this page; i changed the code as below. Which gives me an error 10093.
struct ip_mreq {
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_interface; /* local IP address of interface */
};
SOCKET s;
SOCKADDR_IN localif;
struct ip_mreq mreq;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
localif.sin_family = AF_INET;
localif.sin_port = htons(1234);
localif.sin_addr.s_addr = INADDR_ANY;
bind(s, (SOCKADDR *)&localif, sizeof(localif));
mreq.imr_interface.s_addr = INADDR_ANY; //Writing here my local ip didn't change the result.
mreq.imr_multiaddr.s_addr = inet_addr("224.1.50.15");
int rc = NO_ERROR;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
// Join the group
rc = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq));
if (rc == SOCKET_ERROR)
{
printf("JoinMulticastGroup: setsockopt failed with error code %d\n", WSAGetLastError());
}
else
{
printf("Joined group: ");
//PrintAddress(group->ai_addr, group->ai_addrlen);
printf("\n");
}
Ok, I managed to resolve my issue with the help of the book
Multicast Sockets Practical Guide for Programmers which is written by David Makofske & Kevin Almeroth
Thank's goes to the writers and Zaboj Campula for their efforts.
I hope this post and the answer will help many others in the future. The working code is written below! Compiled with Visual Studio 2017 RC (Console Empty C project)