-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (44 loc) · 1.28 KB
/
index.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
52
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,{
cors: {
origin: "*",
methods: ["GET", "POST"]
}
});
io.on('connection', (socket)=>{
socket.on("getMessage", (data)=>{
console.log("get message: " + JSON.stringify(data))
})
console.log("socket connected")
})
server.listen(3001,()=>{
console.log("server run port 3001")
})
// 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.sendFile(__dirname + '/index.html');
// // // res.links('http://localhost:3000/');
// // });
// io.on('connection', (socket) => {
// console.log('a user connected gago');
// socket.on('chat message', (msg)=>{
// io.emit('chat message', msg);
// console.log("message: " + msg);
// });
// socket.on('disconnect', ()=>{
// console.log("disconnected kana gago")
// });
// });
// server.listen(3001, () => {
// console.log('tang ina mo listening on *:5000');
// console.log('tang inamo')
// });