-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_server.js
38 lines (27 loc) · 897 Bytes
/
socket_server.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
32
33
34
35
36
/* START WEBSOCKET SERVER */
/* LOGGING FUNCTION */
const log = (...optionalParams) => console.log(`Server :`, ...optionalParams);
log('Server starting on http://localhost:815');
const ioServer = require('socket.io')('815', {
cors: {
origin: '*', //'http:localhost:815,
methods: ['GET', 'POST']
}
});
/* NEW CLIENT CONNECTED */
ioServer.on('connection', function (client) {
log('New client connected - ID', client.id);
client.on('socket', function (data) {
log('Daten von Client empfangen: ', data);
if(data = "test"){
ioServer.emit('client', 'hat funktioniert');
}
});
/* CLIENT DISCONNECTED */
client.on('disconnect', function () {
log('Client disconnected - ID ', client.id);
if (ioServer.engine.clientsCount == 0) {
log('No more clients connected - removing lock and arming trigger');
}
});
});