How to do UDP translation using hrome.sockets.udp API?

I am developing a Chrome extension and I want to transfer a UDP packet on a local network.

I learned this Chrome API .

chrome.sockets.udp.create({}, function(s){ chrome.sockets.udp.bind(s.socketId, address, 0, function(ret){ chrome.sockets.udp.send(s.socketId, data, "172.16.0.0", 5019, function(sendinfo){console.log(data.byteLength); console.log(sendinfo);})})}) 

If I specified an address like 172.16.0.0 , the above code is fine. But if I changed 172.16.0.0 to 255.255.255.255 , I got {resultCode: -10} , which indicates an error.

My manifest. json:

 { "manifest_version": 2, "name": "UDP", "description": "Test", "version": "2", "minimum_chrome_version": "23", "app": { "background": { "scripts": ["main.js"] } }, "sockets":{ "udp": {"send":["*:*"], "bind":["*:*"]} }, "permissions":["system.network"] } 
By the way, I tried chrome.socket , which works fine even on air. But the API has been deprecated since Chrome 33.
+7
google-chrome google-chrome-extension udp broadcast
source share
2 answers

Starting with Chrome 44, we have the setBroadcast API.

https://developer.chrome.com/apps/sockets_udp#method-setBroadcast

+4
source share

Not tried yet, but found this:

 "sockets": { "udp": { "bind": "*", "send": "*", "multicastMembership": "" } } 

In this error report

The empty string value for "multicastMembership" not obvious at all, I had to resort to reading unit tests in C ++ to find out the correct value.

+2
source share

All Articles