-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (25 loc) · 711 Bytes
/
index.js
File metadata and controls
34 lines (25 loc) · 711 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
30
31
32
33
34
var express=require("express");
var app=express();
var http=require("http").createServer(app);
var io=require("socket.io")(http);
app.set("view engine", "ejs");
//Criar o evento Connection
//socket é o cliente - uma instância por cada cliente
io.on("connection",(socket) => {
//console.log(socket);
//console.log(socket.id);
socket.on("disconnect",() =>{
console.log(socket.id + " disconnected");
});
socket.on("msg", (data) => {
console.log(data);
//socket.emit("showmsg",data);
io.emit("showmsg",data);
})
});
app.get("/",(req,res) => {
res.render("index");
});
http.listen(3000, () => {
console.log("Servidor a ser executado!");
});