如果节点js找不到客户端html文件会发生什么?

时间:2015-07-23 16:20:25

标签: javascript php node.js socket.io

AM尝试为我的pHP应用程序实现推送服务器。 我最初的想法是,只要我在客户端调用EVENTS就让我们说message_view.php文件。我不会有发出节点js事件的问题。

但是我看到大多数在线教程都使用了我不明白的东西吗?

    fs.readFile(__dirname + '/client.html') ...//html files
    or 
    response.sendfile('hello world') 

他们启动服务器后。然后他们在我的messages_view.php文件中的客户端html文件中添加事件和逻辑,如下所示。

<script src="socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>

和socket发出类似这样的事件:

<script>

// create a new websocket
var socket = io.connect('http://localhost:8000/?profile_id=abcde2');
//..I want to code here to update my  divs.
</script>

我需要什么才能在我的PHP文件上发出此消息。非常感谢!

1 个答案:

答案 0 :(得分:2)

如果你想用php提供html,并且有一个node.js套接字服务器,套接字服务器不需要提供html,所以你可以省略你正在使用的大多数例子。只需在.php中包含提供html页面的脚本,并确保脚本的url正确定位到套接字服务器。