-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (19 loc) · 659 Bytes
/
Copy pathapp.js
File metadata and controls
26 lines (19 loc) · 659 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
const express = require('express')
const app = express()
const socket = require('socket.io')
//Static code
app.use(express.static('public'))
var server = app.listen(3000 , () => {
console.log("Listening to port 3000 , Server started")
})
//socket function takes the server name as the parameter to know on which server wh actually have to setu our socket.io
var io = socket(server)
io.on('connection',function(socket) {
console.log("made socket connection",socket.id)
socket.on('chat',function(data){
io.sockets.emit('chat',data)
})
socket.on('typing',function(data) {
socket.broadcast.emit('typing',data)
})
})