Skip to content

Commit

Permalink
add new msg and create new message
Browse files Browse the repository at this point in the history
  • Loading branch information
paras151 committed Aug 3, 2019
1 parent 9adb6c0 commit 0c2df3d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
12 changes: 1 addition & 11 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
<p>Welcome to body</p>

<script src = "/socket.io/socket.io.js"></script>
<script>
var socket = io();

socket.on('connect',()=>{
console.log("Connected to server")
})

socket.on('disconnect',()=>{
console.log("Disconnected from server")
})
</script>
<script src = "js/index.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions public/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var socket = io();

socket.on('connect',function(){
console.log("Connected to server");

socket.emit('createMessage',{
from:'[email protected]',
text:"Yup,that works for me"
});
});

socket.on('disconnect',function(){
console.log("Disconnected from server")
});

socket.on('newMessage',function(message){
console.log("New Message",message);
})
11 changes: 11 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ io.on('connection',(socket)=>{
socket.on("disconnect",()=>{
console.log("User was disconnected")
})
socket.emit('newMessage',{
from: "John",
text: "See you then",
createAt:"123"
});

socket.on('createMessage',(newMessage)=>{
console.log('createMessage',newMessage);
})

})


var port = process.env.PORT||3000;
server.listen(port,()=>{
console.log("Server started on port "+port)
Expand Down

0 comments on commit 0c2df3d

Please sign in to comment.