I have an small class I trying to implement both TCP messaging and UDP messaging. We have some messages that are to be directed at one person and needs to be guarenteed, and we have update and status messages that need to be broadcasted and not really care if it gets out or not..
I have it down to the part of setsocketopt, which fails once it's hit that line, JUST for the UDP though, TCP side is fine.. The socket is setup, no errors shows everything is good and on setsocketopt, it fails..
The error is 10042 which means, "Bad protocol option", but I found if I ignore the error message the message is still sent and received by the clients.. I would like to remove this error and do it right or is this a norm with UDP?
FOR THE UDP part I have this:
ip_mreq mreq;
mreq.imr_multiaddr.s_addr=inet_addr(ipAddress);
mreq.imr_interface.s_addr=htonl(INADDR_ANY);
if( (sckSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP )) == INVALID_SOCKET )
...
sockaddr_in local;
local.sin_family = AF_INET;
local.sin_port = 0; //automatic assignment: next available
local.sin_addr.s_addr = htonl(INADDR_ANY);
if( bind( sckSocket, (sockaddr*) &local, sizeof(sockaddr_in) ) == SOCKET_ERROR )
...
if( setsockopt( sckSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq) ) == SOCKET_ERROR )
...
srvaddr.sin_family = AF_INET;
srvaddr.sin_port = htons( port );
.......