Skip to content

Instantly share code, notes, and snippets.

@jiridanek
Created February 1, 2014 12:40
Show Gist options
  • Save jiridanek/8751879 to your computer and use it in GitHub Desktop.
Save jiridanek/8751879 to your computer and use it in GitHub Desktop.
Cordova (cca):
// global variables
var data = null;
var port = 4242;
undefined
data = null;
chrome.socket.create('udp', function(s) {
port = port + 1;
console.log("s.socketId: " + s.socketId);
// listen
chrome.socket.bind(s.socketId, '0.0.0.0', port, function(t) {
console.log("t: " + t);
// notice the null for buf size
chrome.socket.recvFrom(s.socketId, null, function(u) {
console.log("recvFrom has data");
data = u;
});
});
// send something?
b = new ArrayBuffer(1);
v = new Uint8Array(b);
v[0] = 42;
console.log(b);
// maybe not
//chrome.socket.sendTo(s.socketId, b, '127.0.0.1', port);
});
s.socketId: 14
ArrayBuffer {}
t: 0
recvFrom has data
undefined
data
Object {resultCode: 0}
// expect data == null
console.log(data);
Object {resultCode: 0}
undefined
Chromium (actually Dartium):
// global variables
var data = null;
var port = 4242;
undefined
//test case, sort of
data = null;
chrome.socket.create('udp', function(s) {
port = port + 1;
console.log("s.socketId: " + s.socketId);
// listen
chrome.socket.bind(s.socketId, '0.0.0.0', port, function(t) {
console.log("t: " + t);
// notice the null for buf size
chrome.socket.recvFrom(s.socketId, null, function(u) {
console.log("recvFrom has data");
data = u;
});
});
// send something?
b = new ArrayBuffer(1);
v = new Uint8Array(b);
v[0] = 42;
console.log(b);
// maybe not
//chrome.socket.sendTo(s.socketId, b, '127.0.0.1', port);
});
undefined
s.socketId: 6 VM128:6
ArrayBuffer {} VM128:20
t: 0 VM128:9
// expect data == null
console.log(data);
null VM129:3
undefined
/////////////////////////////////////////////
// global variables
var data = null;
var port = 4242;
/////////////////////////////////////////////
//test case, sort of
data = null;
chrome.socket.create('udp', function(s) {
port = port + 1;
console.log("s.socketId: " + s.socketId);
// listen
chrome.socket.bind(s.socketId, '0.0.0.0', port, function(t) {
console.log("t: " + t);
// notice the null for buf size
chrome.socket.recvFrom(s.socketId, null, function(u) {
console.log("recvFrom has data");
data = u;
});
});
// send something?
b = new ArrayBuffer(1);
v = new Uint8Array(b);
v[0] = 42;
console.log(b);
// maybe not
//chrome.socket.sendTo(s.socketId, b, '127.0.0.1', port);
});
/////////////////////////////////////////////
// expect data == null
console.log(data);
/////////////////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment