node.jswebsocketjuggernaut

juggernaut file serving


I am developing real-time notifier with juggernaut


As you know, when client try to connect, juggernaut serves files which is in its public directory. so the processing is like this:

(1)browser connect 8080 port (juggernaut listening port)
(2)juggernaut get connection request, and socket connection is completed.
(3)juggernaut send client html files which is its public directory
(4)browser get html and js files from juggernaut, and start communicating with juggernaut.
It works well in my server. this is linux console.

[jinbom@localhost gojug]# juggernaut
2 Sep 17:38:53 - socket.io ready - accepting connections
2 Sep 17:38:57 - Serving / - OK
2 Sep 17:38:57 - Serving /json.js - OK
2 Sep 17:38:57 - Serving /juggernaut.js - OK
2 Sep 17:38:57 - Serving /socket_io.js - OK
2 Sep 17:38:57 - Serving /WebSocketMain.swf - OK


in browser you can see connected result.
enter image description here
But, I do not want to get html and js files from juggernaut. It means that I have web server, and want to integrate the files with my php project files.
In the main page I inserted juggernaut concerned(including connecting) code. this is my main.php page snippet

<script src="http://myhost.org/json.js" type="text/javascript" charset="utf-8"></script>
  <script src="http://myhost.org/socket_io.js" type="text/javascript" charset="utf-8"></script>
  <script src="http://myhost.org/juggernaut.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
    var logElement = document.getElementById("log");
    logElement.value = "";
    var log = function(data){
      logElement.value += (data + "\n");
    };

    var jug = new Juggernaut({
      secure: ('https:' == document.location.protocol),
      host: document.location.hostname,
      port: document.location.port || 80
    });

    jug.on("connect", function(){ log("Connected") });
    jug.on("disconnect", function(){ log("Disconnected") });
    jug.on("reconnect", function(){ log("Reconnecting") });

    log("Subscribing to channel1");

    jug.subscribe("channel1", function(data){
      log("Got data: " + data);
    });

    // Expose for debugging
    window.jug = jug;
  </script>

I just integrate juggernaut's public directory files into my client php files.

When I try to do this, browser cannot connect to juggernaut. I think it's socket.io error. (firebug console)

"NetworkError: 404 Not Found - http://myhost.org:8080/socket.io/1/?t=1314949832960&jsonp=0"

is this wrong? so I have to put them in juggernaut's public directory and have to get them from juggernaut?


Solution

  • I solved this problem by myself.

    I fixed javascript path like this,

    original :

    <script src="http://myhost.org/socket_io.js" type="text/javascript" charset="utf-8"></script>
    <script src="http://myhost.org/juggernaut.js" type="text/javascript" charset="utf-8"></script>
    

    fixed :

    <script src="http://myhost.org:8080/socket_io.js" type="text/javascript" charset="utf-8"></script>
    <script src="http://myhost.org:8080/juggernaut.js" type="text/javascript" charset="utf-8"></script>
    

    yet, I do not understand why this fixing make this problem resolve. anyway works nicely~ ^^; Hope this help.