Jump to content

Join multicast group

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
chiyuwang

chiyuwang

    Newbie

  • Members
  • Pip
  • 1 posts
I am a newbie in socket programming, and wrote a code snipet recently to join a multicast group. But it does not work. setsockopt always return -1. Anyone can help me, thank you in advance.


SOCKET sock;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (INVALID_SOCKET == sock )
return;

struct ip_mreq mreq;
sockaddr_in addrto;
memset(&addrto,0,sizeof(addrto));
addrto.sin_family = AF_INET;
addrto.sin_addr.s_addr = inet_addr("224.1.2.4");
addrto.sin_port = htons(6003);



mreq.imr_multiaddr = addrto.sin_addr;
mreq.imr_interface.s_addr = INADDR_ANY;
int e = setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq));

#2
Ewe Loon

Ewe Loon

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
most ISP's block Multicasting, contact your isp and ask if they do ,