-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (22 loc) · 872 Bytes
/
server.js
File metadata and controls
29 lines (22 loc) · 872 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
28
29
const express = require('express');
const path = require('path');
const app = express();
const http = require('http').createServer(app);
const io = require('socket.io').listen(http);
app.use(express.static(path.join(__dirname, 'build')));
app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'build', 'index.html')));
io.of('/boat').on('connection', socket => {
console.log('joined boat');
socket.on('boat_data', boat_data => {
console.log('boat sent:' + boat_data);
io.of('/clients').emit('boat_data', boat_data);
})
});
io.of('/clients').on('connection', socket => {
console.log('joined clients');
socket.on('client_data', client_data => {
console.log('client sent ' + client_data)
io.of('/boat').emit('client_data', client_data);
})
})
http.listen('5001', () => console.log('listening on *:5001'));