Sorry, gentle reader, this one’s a bit technical.
I was reusing some of the code Apple supply for sending UDP packets between servers, but the system I’m working with listens for broadcast packets. I set it up to use the address 255.255.255.255, but got the EACCESS error: Permission denied
I found an example that did work (without using Apple’s CFSocket class) and did a line by line what’s different. You need this to do broadcast
int broadcastEnable=1;
int ret=setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
if (ret) {
NSLog(@”Error: Could not open set socket to broadcast mode”);
close(sd);
return;
}
If you edit this into Apple’s UDP echo project then it will allow broadcast. Give thanks and praise at http://splinter.com.au/sending-a-udp-broadcast-packet-in-c-objective