vapor-community / sockets

🔌 Non-blocking TCP socket layer, with event-driven server and client.
MIT License
575 stars 54 forks source link

How to enable UDP broadcast ? #134

Closed congyuguo closed 6 years ago

congyuguo commented 7 years ago

When I send message to 192.18.1.255, I get this error: Error Socket failed with code 13 ("Permission denied") [sendFailedToSendAllBytes]. I believe it's because UDP broadcast is disabled by default, so how can I enable it ?

tanner0101 commented 7 years ago

Hmm not quite sure. Possibly you could enable it using a C function and the socket descriptor?

bcast_sock = socket(AF_INET, SOCK_DGRAM, 0);
int broadcastEnable=1;
int ret=setsockopt(bcast_sock, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));

You can access the descriptor with socket.descriptor.raw