node.js - Making xampp and node(socket.io) work together -
i have little web app applies angularjs , php functions , queries database(xampp's apache , mysql). want apply simple chat in web app , not know how configure nor ports , on.
following similar http://socket.io/get-started/chat/
i have index.js such
var app = require('express')(); var http = require('http').server(app); var io = require('socket.io')(http);  app.get('/', function(req, res){    res.sendfile(__dirname + '/index.html');  });  io.on('connection', function(socket){    console.log('a user connected');    socket.on('disconnect', function(){    console.log('user disconnected');    }); });   http.listen(443, function(){   console.log('listening on *:443'); }); i trying port 443 , 80, doesnt seem work (xampp shows 80 , 443, no idea how ports work)
my js file has  var socket = io();
in browser console , i'm getting
socket.io-1.2.0.js:2 http://localhost/socket.io/?io=3&transport=polling&t=1465649664392-0 404 (not found) how resolve problem? expecting output such a user connected in cmd after running node index.js not.
i followed example chat, , works fine without xampp.
your problem socket.io work needs able communicate end on http (e.g. switch protocol). if xampp using port won't work. try xampp forwards requests http://localhost/socket.io/* node.js server.
you can use proxypass directive in apache httpd.conf , like
rewriteengine on rewritecond %{request_uri}  ^/socket.io            [nc] rewritecond %{query_string} transport=websocket    [nc] rewriterule /(.*)           ws://localhost:8000/$1 [p,l]  proxypass        /socket.io http://localhost:8000/socket.io proxypassreverse /socket.io http://localhost:8000/socket.io also make sure required modules enabled
loadmodule proxy_module modules/mod_proxy.so loadmodule proxy_http_module modules/mod_proxy_http.so loadmodule proxy_wstunnel_module modules/mod_proxy_wstunnel.so then you'd have start node.js server on port 8000
http.listen(8000, function(){   console.log('listening on *:8000'); });  
Comments
Post a Comment