mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 02:42:40 +01:00
84731e8f00
Summary: This is purely a prototype at the moment, but the basic functionality sort of works. I'm not sure how far I want to go with this but I think we might be able to get somewhere without it being gross. The idea here is to build a notification server WITHOUT using Comet, since Comet is extremely difficult and complicated. Instead, I use Flash on the client. LocalConnection allows flash instances to talk to each other and connect() can be used as a locking primitive. This allows all the instances to elect a master instance in a race-safe way. The master is responsible for opening a single connnection to the server. On the server, I use Node.js since PHP is pretty unsuitable for this task. See Github Issue #3: https://github.com/facebook/phabricator/issues/3 One thing I need to figure out next is if I can reasonably do SSL/TSL over Flash (it looks like I can, in theory, with the as3crypto library) or if the server needs to just send down version information and trigger a separate Ajax call on the client. Test Plan: Created a client pool and connected it to the server, with election and failover apparently working correctly. Reviewed By: aran Reviewers: Girish, aran, jungejason, tuomaspelkonen, davidrecordon Commenters: Girish, davidrecordon CC: aran, epriestley, Girish, davidrecordon Differential Revision: 284
42 lines
966 B
JavaScript
Executable file
42 lines
966 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="*"/>',
|
|
'</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);
|