Created
August 21, 2015 09:36
-
-
Save chikoski/e34efcf4f69769f8fc9a to your computer and use it in GitHub Desktop.
echo server for Firefox OS
This file contains hidden or 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
| window.addEventListener("load", function() { | |
| console.log("Hello World!"); | |
| var serverSocket = navigator.mozTCPSocket.listen(23451); | |
| var connections = []; | |
| serverSocket.onconnect = function(socket){ | |
| console.log(socket); | |
| connections.push(socket); | |
| socket.ondata = function(event){ | |
| var data = event.data; | |
| console.log(data); | |
| socket.send(data); | |
| }; | |
| socket.onclose = function(){ | |
| var index = connections.indexOf(socket); | |
| if(index >= 0){ | |
| connections.splice(index, 1); | |
| } | |
| console.log("socket closed by client"); | |
| }; | |
| }; | |
| serverSocket.onerror = function(error){ | |
| console.log(error); | |
| } | |
| console.log(serverSocket); | |
| window.addEventListener("beforeunload", function(e){ | |
| console.log("beforeunload"); | |
| connections.forEach(function(socket){ | |
| socket.close(); | |
| }); | |
| serverSocket.close(); | |
| console.log("serverSocket has been closed"); | |
| }); | |
| }); |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1"> | |
| <title>Hello World</title> | |
| <style> | |
| body { | |
| border: 1px solid black; | |
| } | |
| </style> | |
| <!-- Inline scripts are forbidden in Firefox OS apps (CSP restrictions), | |
| so we use a script file. --> | |
| <script src="app.js" defer></script> | |
| </head> | |
| <body> | |
| <!-- This code is in the public domain. Enjoy! --> | |
| <h1>Hello World</h1> | |
| </body> | |
| </html> |
This file contains hidden or 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
| { | |
| "name": "echoServer", | |
| "description": "A Hello World app", | |
| "launch_path": "/index.html", | |
| "icons": { | |
| "16": "/icons/icon16x16.png", | |
| "48": "/icons/icon48x48.png", | |
| "60": "/icons/icon60x60.png", | |
| "128": "/icons/icon128x128.png" | |
| }, | |
| "developer": { | |
| "name": "Your name", | |
| "url": "http://example.com" | |
| }, | |
| "type": "privileged", | |
| "permissions": { | |
| "tcp-socket": { | |
| "description": "create TCP socket" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment