-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (21 loc) · 721 Bytes
/
server.js
File metadata and controls
27 lines (21 loc) · 721 Bytes
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
const express = require('express')
const app = express()
const path = require('path')
const server = require('http').createServer(app)
const io = require('socket.io')(server)
const port = process.env.PORT || 3000
server.listen(port, () => {
console.log('Server listening at port %d', port)
})
// Routing
app.use(express.static(path.join(__dirname, 'public')))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html')
})
io.on('connection', (socket) => {
console.log('got a connection now!')
socket.on('stateUpdate', function(player) {
console.log(Date.now(), 'state update received', player)
io.sockets.emit('stateUpdateForwardedByServer', player)
})
})