Last active
December 11, 2015 07:18
-
-
Save abidibo/4565054 to your computer and use it in GitHub Desktop.
Configuration of APE SERVER, 2 machines, 1 serevr and 1 client
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
GENERAL | |
================= | |
Two machines, 1 server and 1 client | |
The backoffice and frontend applications resides on the server | |
SERVER | |
================= | |
Suppose the server ip on the local netw is 192.168.0.74 | |
ls -la /var/ape | |
total 32 | |
drwxr-xr-x 6 abidibo abidibo 4096 2013-01-18 15:38 . | |
drwxr-xr-x 15 root root 4096 2012-12-21 16:09 .. | |
-rw-rw-r-- 1 abidibo abidibo 412 2012-06-20 10:46 color.js | |
drwxr-xr-x 2 abidibo abidibo 4096 2012-06-20 09:51 commands | |
drwxr-xr-x 2 abidibo abidibo 4096 2012-06-20 09:51 examples | |
drwxr-xr-x 2 abidibo abidibo 4096 2012-06-20 09:51 framework | |
-rwxr-xr-x 1 abidibo abidibo 517 2012-06-20 10:48 main.ape.js | |
drwxr-xr-x 2 abidibo abidibo 4096 2012-06-20 09:51 utils | |
FILE /etc/hosts | |
--------------- | |
192.168.0.74 ape-test.local | |
192.168.0.74 ape.ape-test.local | |
192.168.0.74 0.ape.ape-test.local | |
192.168.0.74 1.ape.ape-test.local | |
192.168.0.74 2.ape.ape-test.local | |
192.168.0.74 3.ape.ape-test.local | |
192.168.0.74 4.ape.ape-test.local | |
192.168.0.74 5.ape.ape-test.local | |
192.168.0.74 6.ape.ape-test.local | |
192.168.0.74 7.ape.ape-test.local | |
192.168.0.74 8.ape.ape-test.local | |
192.168.0.74 9.ape.ape-test.local | |
192.168.0.74 *.ape.ape-test.local | |
FILE /etc/ape/ape.conf | |
---------------------- | |
uid { | |
# "aped" switch to this user/group if it run as root | |
user = daemon | |
group = daemon | |
} | |
Server { | |
port = 6969 | |
daemon = yes | |
ip_listen = 0.0.0.0 | |
domain = ape-test.local | |
rlimit_nofile = 10000 | |
pid_file = /var/run/aped.pid | |
} | |
Log { | |
debug = 1 | |
use_syslog = 0 | |
syslog_facility = local2 | |
logfile = /var/log/ape.log | |
} | |
JSONP { | |
eval_func = Ape.transport.read | |
allowed = 1 | |
} | |
Config { | |
#relative to ape.conf | |
modules = /usr/lib/ape/ | |
modules_conf = /etc/ape/ | |
} | |
FILE /etc/ape/inlinepush.conf | |
----------------------------- | |
password = testpasswd | |
FILE /etc/ape/javascript.conf | |
----------------------------- | |
scripts_path = /var/ape/ | |
FILE /etc/ape/proxy.conf | |
----------------------------- | |
#allowed_hosts = irc.freenode.org:6667, irc.freenode.org:6668, google.com | |
allowed_hosts = any | |
BACKOFFICE APPLICATION EXAMPLE | |
------------------------------ | |
public function send() { | |
$light = $_POST['ctrl-1']; | |
$speed = $_POST['ctrl-2']; | |
$acc = $_POST['ctrl-3']; | |
$APEserver = 'http://ape.ape-test.local:6969/?'; | |
$APEPassword = 'testpasswd'; | |
$cmd = array(array( | |
'cmd' => 'inlinepush', | |
'params' => array( | |
'password' => $APEPassword, | |
'raw' => 'postmsg', | |
'channel' => 'testChannel', | |
'data' => array( //Note: data can't be a string | |
'ctrl-1' => array('value'=>$light), | |
'ctrl-2' => array('value'=>$speed, 'acc'=>$acc) | |
) | |
) | |
)); | |
var_dump($APEserver.rawurlencode(json_encode($cmd))); | |
$data = file_get_contents($APEserver.rawurlencode(json_encode($cmd))); | |
$data = json_decode($data); | |
var_dump($data); | |
if ($data[0]->data->value == 'ok') { | |
echo 'Message sent!'; | |
header("Location: ".$this->_router->linkHref($this->_mdl_name, 'ctrlInterface')); | |
} else { | |
echo 'Error sending message, server response is : <pre>'.$data.'</pre>'; | |
} | |
} | |
FRONTEND APPLICATION EXAMPLE | |
---------------------------- | |
<script type="text/javascript"> | |
var client = new APE.Client(); | |
client.load({'channel': 'testChannel'}); | |
client.addEvent('load', function() { | |
client.core.start({'name': new Date().getTime().toString()}); | |
}); | |
client.onRaw('postmsg', function(params) { | |
var light = params.data['ctrl-1'].value; | |
var speed = params.data['ctrl-2'].value; | |
var acc = params.data['ctrl-2'].acc; | |
if(speed && acc) { | |
mygauge.animate(speed, acc); | |
} | |
mypilot.set(light.toInt()); | |
}) | |
</script> | |
CLIENT | |
================= | |
Configure the hosts file to point to the server: | |
FILE /etc/hosts | |
--------------- | |
192.168.0.74 ape-test.local | |
192.168.0.74 ape.ape-test.local | |
192.168.0.74 0.ape.ape-test.local | |
192.168.0.74 1.ape.ape-test.local | |
192.168.0.74 2.ape.ape-test.local | |
192.168.0.74 3.ape.ape-test.local | |
192.168.0.74 4.ape.ape-test.local | |
192.168.0.74 5.ape.ape-test.local | |
192.168.0.74 6.ape.ape-test.local | |
192.168.0.74 7.ape.ape-test.local | |
192.168.0.74 8.ape.ape-test.local | |
192.168.0.74 9.ape.ape-test.local | |
192.168.0.74 *.ape.ape-test.local | |
FILE APE_JSF/Clients/Javascript.php | |
----------------------------------- | |
File included by the front end application | |
The problem I found here is that when the frequency encreases: | |
n.ape.ape-test.local | |
(n+1).ape.ape-test.local | |
the application stop to work, it would work if I put the n and n+1.ape.ape-test.local | |
in the /etc/hosts file, but then the problem starts again with greater n values... | |
so CUSTOM hard code: | |
line 98: | |
config.frequency = 1; | |
FILE APE_JSF/Demos/config.js | |
---------------------------- | |
To be included in frontend application | |
/*** | |
* APE JSF Setup | |
*/ | |
APE.Config.baseUrl = 'http://ape-test.local/APE_JSF'; //APE JSF | |
APE.Config.domain = 'ape-test.local'; | |
APE.Config.server = 'ape.ape-test.local:6969'; //APE server URL | |
APE.Config.transport = 2; | |
(function(){ | |
for (var i = 0; i < arguments.length; i++) | |
APE.Config.scripts.push(APE.Config.baseUrl + '/Source/' + arguments[i] + '.js'); | |
})('mootools-core', 'Core/APE', 'Core/Events', 'Core/Core', 'Pipe/Pipe', 'Pipe/PipeProxy', 'Pipe/PipeMulti', 'Pipe/PipeSingle', 'Request/Request','Request/Request.Stack', 'Request/Request.CycledStack', 'Transport/Transport.longPolling','Transport/Transport.SSE', 'Transport/Transport.XHRStreaming', 'Transport/Transport.JSONP', 'Transport/Transport.WebSocket', 'Core/Utility', 'Core/JSON'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment