I can receive broadcast packets without any problems within a windows running chrome app. However, when I take that app and compile using the cordova/crosswalk tools I can't seem to receive any packets. I see all the packets in wireshark. My packet is transmitted from: 172.24.0.42 and broadcasted on 172.24.255.255 (a broadcast on 255.255.255.255 does not work on Android, but it does work on the windows chrome app).
This is my (manifest.json):
"sockets":{
"udp": {
"bind": "*"
}
},
"permissions":["system.network" , "power"],
This is my code for my network:
chrome.sockets.udp.create({}, function(socketInfo) {
socketId = socketInfo.socketId;
// Setup event handler and bind socket.
chrome.sockets.udp.onReceive.addListener(onReceive);
chrome.sockets.udp.bind(socketId, "0.0.0.0", 4213, function(result) {
if (result < 0) {
console.log("Error binding socket.");
return;
}
//chrome.sockets.udp.send(socketId, arrayBuffer, '127.0.0.1', 1337, function(sendInfo) {
// console.log("sent " + sendInfo.bytesSent);
// })
//chrome.sockets.udp.setBroadcast(socketId, true, function(){})
});
});
This is when I receive the packets:
var onReceive = function(info) {
if (info.socketId !== socketId)
return;
chrome.sockets.udp.setPaused(socketId, true, function(){}); // Set socket paused; Essentially blocking
//console.log();
///processing of my packet
chrome.sockets.udp.setPaused(socketId, false, function(){}); //unpause socket
};
Edit: I've been trying my best to understand why I can't get any broadcast packets in the chrome app on Android. Unfortunately, I've ran into a wall.
setBroadcasthas been added to the library. You can now callsetBroadcast()to enable broadcast permissions.https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-udp