I want to create a Chrome Packaged App used for LAN only, where one instance serves as a server (session host) and other instances must discover the server and join the session. Can this be achieved with chrome.socket?
I have set up the server like this:
var socket = chrome.socket || chrome.experimental.socket;
socket.create('udp', {}, function(createInfo) {
var publish_socket = createInfo.socketId;
socket.bind(publish_socket, '225.0.0.42', 42424, function (result) {
if (result < 0) console.error(result); // this works fine
socket.recvFrom(publish_socket, null, function(recvFromInfo) {
console.log(recvFromInfo); // UNABLE TO MAKE THIS HAPPEN
});
});
// Chrome won't let me listen for app window closing
var cleanup_timer;
cleanup_timer = setInterval(function(){
if (requesting_window.closed) {
socket.destroy(publish_socket);
clearInterval(cleanup_timer);
}
},
5000
);
});
The socket is bound, I can see it in ss -ua
:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 225.0.0.42:42424 *:*
But the server never seems to receive any data. I have tried sending some data using nc -uv 225.0.0.42 42424
and the chrome.socket API but with no success:
socket.create('udp', {}, function(socketInfo) {
var socketId = socketInfo.socketId;
socket.sendTo(socketId, str2ab("discovering"), '225.0.0.42', 42424, function(writeInfo) {
if (writeInfo.bytesWritten < 0) console.error(writeInfo);
});
});
This results in error code -15
on the client side and nothing on the server side.
I suspect there should be a multicast flag set somewhere but I couldn't find it.
I am using Chrome Version 23.0.1246.0 dev
socket.bind(socketId, "0.0.0.0", 0, function(res) {...})
before thesendTo
line and it stopped complaining when sending the data. Unfortunately I still don't know how to listen to the multicast packets. – Joselow