Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var serv = require('http').Server(app);
- //if request is empty send the index page
- app.get('/', function(req, res) {
- res.sendFile(__dirname + '/client/index.html');
- });
- //if request is for client send them to the client directory
- 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;
- });
- setInterval(function() {
- for(var i in SOCKET_LIST) {
- var socket = SOCKET_LIST[i];
- socket.x++;
- socket.y++;
- socket.emit('newPosition',{
- x:socket.x,
- y:socket.y
- });
- }
- },1000/25);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement