repl.it
@octavelr/

socket-sync

Nodejs

No description

fork
loading
Files
  • index.js
  • public
  • Packager files
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
const path = require('path');

app.get('/', function(req, res){
  res.sendFile(path.join(process.cwd(), "public/index.html"));
}); 

io.on('connection', (socket) => {
    var userid = Math.floor(Math.random() * Math.floor(10));
    console.log('User n° ' + userid + ' connected!');
    socket.on('disconnect', () => {
        console.log('User n° ' + userid + ' disconnected.');
    });
    socket.on('msg', (content) => {
        console.log('User ' + userid + ' : ' + content);
        io.emit('msg', 'User ' + userid + ' : ' + content);
    });
    socket.on('link', (link) => {
        io.emit('link', link);
    });
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
});

http.listen(8080, () => {
    console.log('listening on *:8080');
});
Fetching token
?