Answer the question
In order to leave comments, you need to log in
How to make an Express application and socket.io work on different ports?
Good afternoon
Client:
var socket = io('http://localhost:3000');
socket.emit("chat message", 665, 500, 500);
socket.on("chat message", function(movingEmail, movingX, movingY) {
console.log(movingEmail + ' ' + movingX + ' ' + movingY);
});
var app = require('express')();
var express = require('express');
var exphbs = require('express-handlebars');
var path = require('path');
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.set('views', path.join(__dirname, 'views'));
app.engine('hbs', exphbs({defaultLayout:'layout'}));
app.set('view engine', 'hbs');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res) {
res.render('system', {layout: false});
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
console.log('message: ' + msg);
socket.emit('chat message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
var socket = io('http://localhost:3001');
var io = require('socket.io')(3001);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question