I try to push data to browser by java socket. I try to find the
solution and I found this 
http://www.ape-project.org/wiki/index.php/Libape-controller

I configure ape.main.js like this:

Ape.addEvent("init", function() {
        include("framework/mootools.js");
        include("framework/Http.js");
        include("framework/userslist.js");
        include("utils/utils.js");
        include("commands/proxy.js");
        include("commands/inlinepush.js");
        include("examples/nickname.js");
        include("examples/move.js");
        include("utils/checkTool.js"); //Just needed for the APE JSF
diagnostic tool, once APE is installed you can remove it
        //include("examples/ircserver.js");
        //include("framework/http_auth.js");
        include("examples/server.js");
});





And configure "examples/server.js" like this:

/* Listen on port 6970 (multicast) and high performences server */
/* Check ./framework/proxy.js for client API */

var socket = new Ape.sockServer(6970, "0.0.0.0", {
        flushlf: true /* onRead event is fired only when a \n is received
(and splitted around it) e.g. foo\nbar\n  will call onRead two times
with "foo" and "bar" */
});

/* fired when a client is connecting */
socket.onAccept = function(client) {
        Ape.log("New client");
        client.write("Hello world\n");
        client.foo = "bar"; // Properties are persistants
        //client.close();
}

/* fired when a client send data */
socket.onRead = function(client, data) {
        Ape.log("Data from client : " + data);
}

/* fired when a client has disconnected */
socket.onDisconnect = function(client) {
        Ape.log("A client has disconnected");

}

Ape.log("Listen on port " + port + '...');





client (test.html) :
    <script type="text/javaScript">
            //Instantiate APE Client
            var client = new APE.Client();

            //Load APE Core
            client.load();

            //Intercept 'load' event. This event is fired when the
Core is loaded and ready to connect to APE Server
            client.addEvent('load', function() {
                //Call the core start function to connect to APE
Server
                client.core.start({"name":prompt('Your name?')});
            });

            //4) Listen for the ready event to know when your client
is connected
            client.addEvent('ready', function() {
                console.log('Your client is now connected');
                //1) join 'testChannel'
                client.core.join('test');

                //2) Intercept multiPipeCreate event
                client.addEvent('multiPipeCreate', function(pipe,
options) {
                //3) Send the message on the pipe
                pipe.send('PICHARNAN');
                    console.log('Sending PICHARNAN');
                });

                //4) Intercept receipt of the new message.
                client.onRaw('data', function(raw, pipe) {
                    console.log('Receiving : ' +
unescape(raw.data.msg));
                                        alert(raw.data.msg + " Pipe : " + pipe);
                });
            });
        </script>




Last , java file :

import java.io.PrintWriter;
import java.net.Socket;
import org.json.simple.JSONObject;

public class APE {

        /**
         * @param args
         */
        public static void main(String[] args) {
                try
                {
                        String host="192.168.0.242";
                        int port = 6970;
                        String channel="test";
                        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");
                    System.out.println(root.toString());
                    out.println(root.toString());
                        out.close();
                        socket.close();
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                }
        }


I restart ape-server and run java file, result is nothing occur with
client browser.
I'm sure that client can do correct because I test by 2 client and
result is can send and receive between browser.

Who has solution, tell me please ??

ps. sorry for my bad English

-- 
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/

Reply via email to