Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to establish connection using Socket and Node.js

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 285
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: