如果节点 js 找不到客户端 html 文件会怎样?
What happens if node js doesn't find a client html file?
AM 正在尝试为我的 pHP 应用程序实施推送服务器。
我最初的想法是只要我保持在我的客户上调用的事件让我说 message_view.php 文件。我不会有发出节点 js 事件的问题。
但是我看到大多数在线教程都使用类似我不明白的东西?
fs.readFile(__dirname + '/client.html') ...//html files
or
response.sendfile('hello world')
在他们启动服务器之后。然后他们在客户端 html 文件中添加事件和逻辑,这些事件和逻辑应该在我的 messages_view.php 文件中执行。
<script src="socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
和套接字发出这样的事件:
<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 文件中发出此消息。非常感谢!
如果你想用 php 服务 html,并且有一个 node.js 套接字服务器,套接字服务器不需要服务 html,所以你可以省略您正在使用的大部分示例。只需将脚本包含在为 html 页面提供服务的 .php 中,并确保脚本的 url 正确定位套接字服务器。
AM 正在尝试为我的 pHP 应用程序实施推送服务器。 我最初的想法是只要我保持在我的客户上调用的事件让我说 message_view.php 文件。我不会有发出节点 js 事件的问题。
但是我看到大多数在线教程都使用类似我不明白的东西?
fs.readFile(__dirname + '/client.html') ...//html files
or
response.sendfile('hello world')
在他们启动服务器之后。然后他们在客户端 html 文件中添加事件和逻辑,这些事件和逻辑应该在我的 messages_view.php 文件中执行。
<script src="socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
和套接字发出这样的事件:
<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 文件中发出此消息。非常感谢!
如果你想用 php 服务 html,并且有一个 node.js 套接字服务器,套接字服务器不需要服务 html,所以你可以省略您正在使用的大部分示例。只需将脚本包含在为 html 页面提供服务的 .php 中,并确保脚本的 url 正确定位套接字服务器。