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
net.createServer( | |
function(socket) | |
{ | |
/** | |
* Start the flash policy file | |
*/ | |
socket.write("<?xml version=\"1.0\"?>"); | |
socket.write("<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">\n"); | |
socket.write("<cross-domain-policy>\n"); | |
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
var sys = require("sys"), | |
ws = require('./lib/ws'); | |
var server = ws.createServer(); | |
intervals = {}; | |
server.addListener("listening", | |
function() | |
{ | |
sys.log("Listening for connections."); |
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
// Handle WebSocket Requests | |
server.addListener("connection", | |
function(conn) | |
{ | |
conn.send("Connection: "+conn.id); | |
sys.log("Connection found: " + conn.id); |
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
conn.addListener("message", | |
function(message) | |
{ | |
sys.log("Message recieved from conn# " + conn.id + "\ | |
" + message); | |
} | |
); |
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
server.addListener("close", | |
function(conn) | |
{ | |
clearInterval(intervals[conn]); | |
server.broadcast("<"+conn.id+"> disconnected"); | |
sys.log(conn.id + " disconnected"); | |
} | |
); |
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
var ws = new WebSocket("ws://localhost:40132"); | |
ws.onopen = function() | |
{ | |
output("Opened connection."); | |
}; | |
ws.onmessage = function(e) | |
{ | |
date = new Date(e.data); | |
if(isNaN(date.getHours())) | |
{ |
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
</script> | |
</head> | |
<body> | |
<div id="log"></div> | |
</body> | |
</html> |
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
sudo node flashpolicy.js > flashpolicy.log & sleep 5; tail flashpolicy.log |
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
var arr = // array of objects; | |
res = []; | |
arr.forEach(function (item) { | |
item.save(function (err) { | |
res.push(err); | |
if (res.length === arr.length) | |
{ | |
// Done | |
} |
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
// One-shot set function | |
function error (fn) | |
{ | |
// Create locally bound copy of `fn` | |
var handle = fn.bind(this); | |
// Overwrite function | |
error = handle; | |
} |