JS Inlinepush

Louis Charette edited this page Apr 19, 2014 · 1 revision

Normal users can interact with the APE server via the browser. But External parties can also interact with the Ape server if you allow them to send their requests to your api's. APE server will process the command, and can propagate its results to the apropiate users. So you could interface a legacy system to send out updates to ape, witch on turn pushes it further to the users.

PHP example

The php example is simple and to the point. It is shippped in the Controller demo (included in the APE JSF) and in Ape Server in the demo scripts:

Python example

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())

JAVA example

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();
		}		
	}
}