Advertisement

Multicasting problem

Started by December 06, 2003 01:09 AM
2 comments, last by Pip 21 years, 2 months ago
Im trying the GameDev Multicasting tutorial and Im getting a error with setsockopt(). Its throwing a WSAENOPROTOOPT defined by msdn as "The option is unknown or unsupported for the specified provider or socket." I have used the code that was used in the tutorial and its giving me that error. Does anyone have any idea why it doesnt like the option "IPPROTO_IP, IP_ADD_MEMBERSHIP"? Here is my code for the socket: int WSAProcess; int MyUDPSocket; WSAData WsaData; if((WSAProcess = WSAStartup(MAKEWORD(2,2),&WsaData)) == SOCKET_ERROR) { printf("ERROR: Failed to start up WinSock...\n"); return -1; } if((MyUDPSocket = socket(AF_INET,SOCK_DGRAM,0)) == SOCKET_ERROR) { printf("ERROR: Failed to create UDP socket...\n"); return -1; } SOCKADDR_IN addrLocal; addrLocal.sin_family = AF_INET;// We want to use the Internet address family addrLocal.sin_addr.s_addr = INADDR_ANY;// Use any local address addrLocal.sin_port = htons(Port); // Use arbitrary port - but the same as on other clients/servers if(SOCKET_ERROR == bind(MyUDPSocket, (LPSOCKADDR)&addrLocal,sizeof(struct sockaddr)))// Bind socket to our address { printf("ERROR: UDP bind failed..."); return -1; } // Ready to switch to multicasting mode struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = inet_addr(MultiCastGrp); mreq.imr_interface.s_addr = INADDR_ANY; /******************************************************** This is where im getting the error from *********************************************************/ if((WSAProcess = setsockopt(MyUDPSocket,IPPROTO_IP,IP_ADD_MEMBERSHIP,(char*)&mreq,sizeof(mreq))) == SOCKET_ERROR) { int error = WSAGetLastError(); switch(error) { case WSAEINVAL: printf("ERROR: WSAEINVAL thrown."); break; case WSAENOTSOCK: printf("ERROR: WSAENOTSOCK thrown."); break; case WSAENOPROTOOPT: printf("ERROR: WSAENOPROTOOPT thrown."); break; } printf("ERROR: Membership failed...\n"); return -1; } /**************************************************************/ unsigned long num; if((ioctlsocket(MyUDPSocket,FIONBIO,#))==SOCKET_ERROR) { printf("ERROR: ioctlsocket() failed on UDP"); } char TTL = 32; // Restricts threshold to same site if((setsockopt(MyUDPSocket, IPPROTO_IP, IP_MULTICAST_TTL,(char *)&TTL, sizeof(TTL))) == SOCKET_ERROR) { printf("ERROR: setsockopt() failed on UDP"); } return MyUDPSocket; [edited by - Pip on December 6, 2003 2:12:09 AM] [edited by - Pip on December 6, 2003 2:15:05 AM]
The values for IP_ADD_MEMBERSHIP differ from winsock1 to winsock2. Be sure your code is seeing the correct definition from ws2tcpip.h instead of winsock.h. Your actual code looks like it should work.
Advertisement
How do I do that? I tried #include <ws2tcpip.h> and got alot of errors.
Make sure your system supports Winsock2 and include all the proper headers; windows.h, winsock2.h and ws2tcpip.h in that order I think. You will also have to link to the proper library, ws2_32.lib.

This topic is closed to new replies.

Advertisement