I'm working on a Google Chrome app that contains the following code:
var socket = chrome.sockets.udp;
var PORT = 5005;
var HOST = '127.0.0.1';
socket.create({}, function(sockInfo){
socket.bind(sockInfo.socketId, HOST, PORT, function(result){
socket.onReceive.addListener(function(info){
// do stuff with the packet data
});
});
});
This mechanism worked perfectly when I was sending data on a looparound from localhost. However, when I try to send from a remote machine, the onReceive.addListener callback function never gets called. At first I thought this might be a local network issue, but when I tcpdump -vv udp port 5005
it reads the data I'm sending, so I know it's reaching my machine. This leads me to believe it's a Chrome issue...in my manifest.json file I've set universal "bind" and "send" permissions for UDP, so I don't see why this isn't working. Any thoughts?
François Beaufort's now deleted answer provided a useful suggestion, sadly in a way that was more appropriate for a comment. I'm making this a community wiki so that he does not feel robbed of reputation.
The
HOST
part indicates which interface you're listening on for data. Setting it to127.0.0.1
means that you're only listening for the loopback interface, that is not accessible from outside.You could provide an explicit IP address of the network interface you have, but an easier solution is to say "I want to listen on them all".
Quote from the docs:
That should solve it in your case; in general, one also needs to check that the firewall is letting the requests through; you already did it.