1
我正在嘗試爲現有的PHP項目構建node.js聊天功能。我正在使用node.js socket.io。 Node.js正在監聽端口3000.現在的問題是,當我嘗試訪問聊天PHP頁面http://www.example.com:3000/app/chat.php頁面被下載而不是被服務。我知道node.js不提供PHP頁面,但可以爲同樣的方法做什麼解決方法?如何將數據從node.js服務器傳遞到Apache服務的PHP頁面?
Node.js的
var app = require('express')(),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
httpProxy = require('http-proxy');
server.listen(3000);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.php');
});
io.sockets.on('connection', function(socket) {
socket.on('send data',function (data) {
io.sockets.emit('latest data',data);
});
});
PHP
<?php
// Blah Blah
<script>
jQuery(function($))
{
var socket = io.connect();
var $editArea = $('#editAreaID');
$editArea.keydown(function(){
socket.emit('send data', $editArea.val());
});
socket.on('latest data', function(data){
$editArea.val(data);
});
}
</script>
// Blah Blah
?>
你可以張貼請 –
是不是Apache就'www.example.com /應用/ chat.php'運行的代碼?如果你使用節點進行聊天,你爲什麼還需要PHP? –
服務器端 - > http://pastebin.com/DQR7jP8P 客戶端 - > http://pastebin.com/icigaBgk – Siddharth