-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrash.js
51 lines (40 loc) · 1.03 KB
/
trash.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
46
47
48
49
50
51
var express = require("express");
var app = express();
app.use(express.static("./public"));
app.set("view engine", "ejs");
app.set("views", "./views");
var server = require("http").Server(app);
var io = require("socket.io")(server);
const mysql = require("mysql");
// var sql = mysql.createConnection({
// host: "127.0.0.1",
// user: "root",
// password: "",
// database: "NodeJs"
// });
// sql.connect(err => {
// if (err) {
// console.log("error", err);
// return;
// }
// console.log("SQL connect Successfully");
// });
server.listen(3000);
//io.sockets.emit
//socket.emit
//socket.broadcast.emit
//io.to("socketId").emit()
io.on("connection", socket => {
let count = 0;
console.log("Connect", socket.id);
socket.on("disconnect", () => {
console.log("disconnect", socket.id);
});
socket.on("message", message => {
console.log("receive message: ", message, "from ", socket.id);
io.sockets.emit("message", message + `${count++}`);
});
});
app.get("/", (req, res) => {
res.render("index");
});