Q:

Call a function through socket.io

Here i have a button which shows alert box onclick. I'm trying to implement client and server model where data is transferred between client and server. Now when i open the script in two windows, and when i click the button in one window alert should be displayed in both windows, This indicates that user in one windows thinks that the user in another window clicked the button.
here is my index.html file
<html>
<head>

<script>
function myFunction() {
    alert("I am an alert box!");
}
</script>

</head>
<body>

<button id="datasend " type="button " ng-click="doPost "onclick="myFunction()">Send!
</button>

</body>
</html> 

Here is my app.js 
 $scope.doPost = function () {

                myFunction();

        socket.emit('sendmessage', function (){

                myFunction();
            });

        socket.on('sendmessage', function () {

                $('#datasend').click(function()
      {

      });
            });
          }

A:

You can start a VERY basic node server:
server.js
const io = require('socket.io')(3000);
io.on('connection', function (socket) {
    console.log('a client has connected');
    socket.on('clicked', function() {
        io.emit('clicked');
    });
});
console.log('socket.io server started at port 3000'); 

and open the following index.html in several tabs of your browser:
index.html
<!doctype html>
  <html>
    <head>
      <title>Testing socket.io</title>
    </head>
    <body>
      <button id="button">Send!</button>
      <h2 id="alert"> waiting...</h2>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script>
      <script>
        var socket = io("http://localhost:3000");
        socket.on('connect', function() {
          document.getElementById("button").addEventListener("click", function () {
              socket.emit("clicked");
          });
        });
        socket.on('clicked', function() {
          console.log('clicked');
          document.getElementById("alert").innerHTML = "button clicked";
        });
      </script>
    </body>
  </html>

