Hello Readers,
The most important thing to use Node and Socket is to make connection. For this we should have two files one is Client.js(i.e. Client Side Javascript file) and other is Server.js(Server side javascript file).
Under Client.js file:
At the head include this script.
<script src="/socket.io/socket.io.js"></script>
var socket = io('http://localhost');
</script>
Under Server.js file
io.on('connection', function (socket) {
console.log("Hello World");
});
Whenever the User comes it will call var socket = io('http://localhost') . It means now it will go to Server.js file and finds the io.on('connection', function (socket) , and do the stuffs whatever you wants to do inside io.on('connection')
0 Comment(s)