-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (20 loc) · 732 Bytes
/
app.js
File metadata and controls
30 lines (20 loc) · 732 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
var express = require("express");
var socket = require("socket.io");
var app=express();
var server = app.listen(3000,function(){
console.log("connected to port number 3000!!!");
});
//lets put the static files here
app.use(express.static("public"));
var io = socket(server); //the socket is setup between the server and the frontend
io.on("connection",function(socket){ //"connection" event takes place!!!
console.log("socket connection is established!!!");
socket.on("chat",function(data){
io.emit("chat",data);
});
socket.on("typing",function(data){
socket.broadcast.emit("typing",data);
});
});
//socket.id
//the param socket gets a new ID everytime it is set up...!!!