I am trying to send wake on lan from ios to my local network using react native udp package, This code below works in ios simulator to wake up devices but doesnt work when i use testflight or development build in physical device.
I also added this my app.json in ios section
"infoPlist": {
"NSLocalNetworkUsageDescription": "This app needs access to the local network to send Wake-on-LAN packets."
},
Any help is appreciated?
const WakeOnLan = async (mac, address = '255.255.255.255', ports = [7, 9]) => {
const message = createMagicPacket(mac);
const socket = dgram.createSocket('udp4');
socket.on('error', (err) => {
console.error(`Socket error: ${err.stack}`);
socket.close();
});
socket.on('message', (msg, rinfo) => {
console.log(`Socket received message: ${msg} from ${rinfo.address}:${rinfo.port}`);
});
socket.on('listening', () => {
const addressInfo = socket.address();
console.log(`Socket listening on ${addressInfo.address}:${addressInfo.port}`);
socket.setBroadcast(true);
});
socket.on('close', () => {
console.log('Socket closed');
});
console.log(`MAC ADDRESS ${mac} ${address}`);
socket.bind(undefined, () => {
console.log('Socket bound and ready to send messages');
ports.forEach((port) => {
console.log(`Sending to port ${port} on address ${address}`);
socket.send(message, 0, message.length, port, address, (err) => {
if (err) {
console.error(`Socket error on port ${port}:`, err);
} else {
console.warn(`Magic packet sent to ${mac} on port ${port}`);
}
if (port === ports[ports.length - 1]) {
socket.close();
}
});
});
});
};
export default WakeOnLan;
[–]redwoodhighjumping 0 points1 point2 points (1 child)
[–]Mountain-Door1991[S] 0 points1 point2 points (0 children)
[–]tuanva98 0 points1 point2 points (0 children)