From Ape Wiki
[edit] Inlinepush
Take a look to the Controller demo (included in the APE JSF) :
- PHP : http://github.com/APE-Project/APE_JSF/blob/master/Demos/Controller/test.php
- JavaScript : http://github.com/APE-Project/APE_JSF/blob/master/Demos/Controller/demo.js
- HTML : http://github.com/APE-Project/APE_JSF/blob/master/Demos/Controller/demo.html
[edit] Python Sample code
Here's an example of the above PHP code written in Python (version 2.6).
import urllib2 import json server = 'http://127.0.0.1:6969/0/?' cmd = [{'cmd': 'inlinepush', 'params': { 'password': 'testpasswd', 'raw': 'mailnotif', 'channel': 'testchannel', 'data': { 'content': 'Heyyyy' } } }] url = server + urllib2.quote(json.dumps(cmd)) response = urllib2.urlopen(url) print(response.html())
[edit] JAVA Sample code
import java.io.PrintWriter; import java.net.Socket; import org.json.JSONObject; /* * Author: Claude Hussenet 7/5/2011 * * Simple JAVA program opening a socket and sending JSON object to the APE server * Dependency with the library from Douglas Crockford at https://github.com/douglascrockford/JSON-java * which can be easily removed * * Configuration on the APE server * 1-Include examples/server.js in ape.main.js * 2-Insure that the port number listed in server.js matches the one listed below. * 3-Restart your APE server * * Client side * * 1-Join the channel specified below. * Ex:client.core.join("ChannelToListenFrom"); * 2-Listen messages by implementing the following code * client.onRaw('data', function(raw, pipe) { * alert(raw.data.msg); * }); */ public class PushToAPEServer { public static void main(String[]args) { try { String host="APEServerHostName"; int port = 6970; String channel="ChannelToListenFrom"; Socket socket = new Socket(host, port); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); JSONObject root = new JSONObject(); JSONObject message = new JSONObject(); message.put("msg","Bonjour from NY"); root.put("data", message); root.put("channel",channel); root.put("raw","data"); out.println(root.toString()); out.close(); socket.close(); } catch (Exception e) { e.printStackTrace(); } } }


