1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00
phorge-phorge/support/aphlict/server/aphlict_server.js
epriestley f8431bbfee Make Aphlict client somewhat more approachable
Summary: Provide a reasonable JS API for the Aphlict client. Provide an example behavior to invoke it.

Test Plan:
Ran "aphlict_server.js" with:

  $ sudo node aphlict_server.js

Loaded /aphlict/. Opened console. Got "hello" from the server every second.

Got reasonable errors with the server not present ("Security exception", but this is because it can't connect to port 843 to access the policy server).

Reviewers: ddfisher, keebuhm, allenjohnashton, btrahan

Reviewed By: btrahan

CC: aran, epriestley

Maniphest Tasks: T944

Differential Revision: https://secure.phabricator.com/D1800
2012-03-06 20:14:03 -08:00

42 lines
969 B
JavaScript
Executable file

var net = require('net');
function getFlashPolicy() {
return [
'<?xml version="1.0"?>',
'<!DOCTYPE cross-domain-policy SYSTEM ' +
'"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">',
'<cross-domain-policy>',
'<allow-access-from domain="*" to-ports="2600"/>',
'</cross-domain-policy>'
].join("\n");
}
net.createServer(function(socket) {
socket.on('data', function() {
socket.write(getFlashPolicy() + '\0');
});
}).listen(843);
var sp_server = net.createServer(function(socket) {
function xwrite() {
var data = {hi: "hello"};
var serial = JSON.stringify(data);
var length = Buffer.byteLength(serial, 'utf8');
length = length.toString();
while (length.length < 8) {
length = "0" + length;
}
socket.write(length + serial);
console.log('write : ' + length + serial);
}
socket.on('connect', function() {
xwrite();
setInterval(xwrite, 1000);
});
}).listen(2600);