Can you help me fix my code? [Socket.io not working.] #5204
Unanswered
mcherryportfolio
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm working on a html online video game. I need help I think socket.io is not working.
This is the code down below.
var express = require('express');
var app = express();
var serv = require('http').Server(app);
app.get('/',function(req, res) {
res.sendFile(__dirname + '/client/index.html');
});
app.use('/client',express.static(__dirname + '/client'));
serv.listen(2000);
console.log("Server started.");
var SOCKET_LIST = {};
var io = require('socket.io')(serv,{});
io.sockets.on('connection', function(socket){
socket.id = Math.random();
socket.x = 0;
socket.y = 0;
SOCKET_LIST[socket.id] = socket;
console.log('socket connection');
});
setInterval(function() {
for(var i in SOCKET_LIST){
var socket = SOCKET_LIST[i];
socket.x++;
socket.y++;
socket.emit('newPostion',{
x:socket.x,
y:socket.y,
});
}
},1000/25);
The output on console is : [See Photo]

Beta Was this translation helpful? Give feedback.
All reactions