You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
678 B
JavaScript
29 lines
678 B
JavaScript
const express = require('express');
|
|
const app = express();
|
|
const http = require('http');
|
|
const server = http.createServer(app);
|
|
const { Server } = require('socket.io');
|
|
const io = new Server(server);
|
|
|
|
app.get('/', (req, res) => {
|
|
//res.send('<h1> Hello Angelus!</h1>');
|
|
res.sendFile(__dirname + '/index.html');
|
|
});
|
|
|
|
io.on('connection',(socket) => {
|
|
console.log ('A new user is connected');
|
|
//disconect
|
|
socket.on('disconnect',() => {
|
|
console.log("A user has been disconnect");
|
|
});
|
|
// more functions
|
|
socket.on('chat message', (msg) => {
|
|
console.log(msg);
|
|
io.emit('chat message', msg);
|
|
});
|
|
});
|
|
|
|
server.listen(3333, () => {
|
|
console.log('listen on part 3333');
|
|
});
|