socket.io - How do I point to my node.js server within my PHP app? -
i have php application, adding real time capabilities using node.js , socket.io
while experienced php node.js , finding myself going round in circles.
i have installed both node.js , socket.io. have created /usr/local/lib/app.js containing following example code socket.io site:
var app = require('http').createserver(handler) , io = require('socket.io').listen(app) , fs = require('fs') app.listen(3000); function handler (req, res) { fs.readfile(__dirname + '/index.html', function (err, data) { if (err) { res.writehead(500); return res.end('error loading index.html'); } res.writehead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); when run node /usr/local/lib/app.js info - socket.io started far appears work correctly.
however next step add script client connect socket.io server upon load.
within php app adding following:
<script src="http://xx.xx.xx.xx:3000/socket.io/socket.io.js"></script> <script> var socket = io.connect('http://localhost'); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); }); </script> with sites ip address in places of xx's. request socket.io.js file returns 404 error.
i not grasping something. can help.
Comments
Post a Comment