-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (34 loc) · 1.28 KB
/
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
37
38
39
40
41
42
43
44
45
//=============================================================================
// DECLARE ALL THE VARIABLE FOR THE Applications
//=============================================================================
const express = require('express');
const app = express();
const server = app.listen(3000,console.log("Socket.io Hello World server started!"));
const io = require('socket.io')(server);
var data = {
name: 'etienne',
prenom: 'fuh',
data: '11-12-2022'
};
//=============================================================================
// ROUTAGE FOR THE APP
//=============================================================================
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html')
})
//=============================================================================
// INITIALIZE THE SOCKET
//=============================================================================
io.on('connection', (socket) => {
console.log("Client connected!");
socket.on('disconnect', socket => {
console.log("user disconneted ")
})
socket.on('chat', function(msg){
console.log('message recu : ' + msg);
io.emit('chat' , msg);
})
socket.on('data' , (data) => {
io.emit('data', data);
})
})