node.js - expressjs socket.io port 3000 is already in use -
should need to specify different ports express (3000) , socket.io?
error: port 3000 in use
my code:
index.js
var express = require('express') ,router = express.router() , app = express() , http = require('http') , server = http.server(app) , io = require('socket.io').listen(server) server.listen(3000); router.get('/', function(req, res, next) { res.render('index', { title: 'express' }); }); io.on('connection',function(socket){ console.log("a user connected"); socket.on('point1', function (value) { socket.broadcast.emit('point1',value); }); socket.on('less1', function (value) { socket.broadcast.emit('less1',value); }); socket.on('point2', function (value) { socket.broadcast.emit('point2',value); }); socket.on('less2', function (value) { socket.broadcast.emit('less2',value); }); }); module.exports = router;
index.html
<script src="/socket.io.js"></script> <script type="text/javascript"> var socket = io.connect(); </script>
or how can pass variable on io.connect("use-host:use-port");
on index.html app.js or config file.
Comments
Post a Comment