开发者

juggernaut file serving

开发者 https://www.devze.com 2023-04-01 06:40 出处:网络
I am developing real-time notifier with ju开发者_如何学编程ggernaut As you know, when client try to connect,

I am developing real-time notifier with ju开发者_如何学编程ggernaut

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.

juggernaut file serving

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消