Server.js Code
var express=require ("Express"), Pipe=require ("./pipe.js"), app=express (), http=require (' http '). Createserver (APP) sio=require (' Socket.io '). Listen (HTTP);//Do.......sio.on (' Connection ', function (socket) { console.log (' connection '); Socket.on (' msg ', function (a) { console.log (a); Sio.emit (' msg ', ' Your Sister ');}) ; App.listen (7777,function () { Console.log ("app started Port is 7777");
After performing node Server.js run
Access/socket.io/socket.io.js to 404 on the browser
It took one hours to finally fix it.
It would be nice to change App.listen to Http.listen.
var express=require ("Express"), Pipe=require ("./pipe.js"), app=express (), http=require (' http '). Createserver (APP) sio=require (' Socket.io '). Listen (HTTP);//js merge pipe (app);//Shopping cart require ("./cart.js") (app); App.engine ("HTML", require ("./lib/tpl-node.js"));//require ('./test/websocket.js ') (app); app.gome={ static: "E : \\workspaces\\dev\\Storefront\\storedocroot.war ", jsserver:" http://localhost:7777 ", };app.use ( Express.static (app.gome.static)); App.use (Express.static ('./test ')); App.get ("/", function (req,res) { res.send ("index"). end ();}); Sio.on (' Connection ', function (socket) { console.log (' connection '); Socket.on (' msg ', function (a) { console.log (a); Sio.emit (' msg ', ' Your Sister ');}) ; Http.listen (7777,function () { Console.log ("app started Port is 7777");
The following is a complete server and client JS
Server.js
var express=require ("Express"), Pipe=require ("./pipe.js"), app=express (), http=require (' http '). Createserver (APP) sio=require (' Socket.io '). Listen (HTTP);//js merge pipe (app);//Shopping cart require ("./cart.js") (app); App.engine ("HTML", require ("./lib/tpl-node.js"));//require ('./test/websocket.js ') (app); app.gome={ static: "E : \\workspaces\\dev\\Storefront\\storedocroot.war ", jsserver:" http://localhost:7777 ", };app.use ( Express.static (app.gome.static)); App.use (Express.static ('./test ')); App.get ("/", function (req,res) { res.send ("index"). end ();}); Sio.of ('/test '). On (' Connection ', function (socket) { console.log (' connection '); Socket.on (' msg ', function (a) { console.log (a); Socket.emit (' msg ', ' Your Sister ');}) ; Http.listen (7777,function () { Console.log ("app started Port is 7777");
Client.js
<! DOCTYPE html>
Node Express4.0+socket.io consolidated access to socket.io.js issues