mirror of
https://github.com/zhigang1992/examples.git
synced 2026-06-11 07:44:14 +08:00
20 lines
409 B
JavaScript
20 lines
409 B
JavaScript
const app = require('express')();
|
|
const http = require('http').Server(app);
|
|
const io = require('socket.io')(http);
|
|
|
|
app.get('/', function(req, res){
|
|
res.sendfile('index.html');
|
|
});
|
|
|
|
io.on('connection', function(socket){
|
|
console.log('a user connected');
|
|
});
|
|
|
|
setInterval(() => {
|
|
io.emit('ping', { data: (new Date())/1});
|
|
}, 1000);
|
|
|
|
http.listen(3000, function(){
|
|
console.log('listening on *:3000');
|
|
});
|