Created
November 19, 2014 19:22
-
-
Save timgluz/a15303d8b8c207a9e00f to your computer and use it in GitHub Desktop.
Little working example for `navigator.mozTCPSocket.listen`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
PS: | |
1. you need simulator > 2.2 | |
2. manifest.app must include: | |
"type": "privileged", | |
"permissions": { | |
"tcp-socket" : { | |
"description" : "Create TCP sockets and communicate over them." | |
} | |
*/ | |
function startListen(){ | |
console.log("Initializing server"); | |
var socketServer = navigator.mozTCPSocket.listen(8080); | |
socketServer.onconnect = function(conn){ | |
console.log("connected", conn); | |
conn.send("Ok. Got client on: ", conn.port); | |
conn.ondata = function(ev){ | |
console.log("Got request: ", ev); | |
}; | |
conn.onclose = function(ev){ | |
console.log("Client left:", ev); | |
} | |
conn.close(); //get request and leave; HTTP thingy | |
}; | |
socketServer.onerror = function(ev){ | |
console.log("Failed to start: ", ev); | |
}; | |
} | |
startListen(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment