var http = require("http"); var ws = require("webscoket-server"); var httpserver = new http.Server(); var clientui = require(‘fs‘).readFileSync("webchat.html"); httpserver.on("request",function(request,response){ if(request.url ==="http://www.mamicode.com/"){ response.writerHead(200,{"Content-Type":"text/html"}); response.write(); response.end(); }else{ response.writeHead(404); response.end(); } }); var wsserver = ws.createServer({server:httpserver}); wsserver.on("connection",function(socket){ scoket.send("w t caht room"); socket.on("message",function(msg){ wsserver.broadcast(msg); }); }); wsserver.listen(8000);
,