Speed up development with full-stack environments for every branch.

Learn More

Sending and receiving events with socket.io

2830 Runs 9171 Views 1989 Copies
Saved

Saved

sundip 66

sundip
published 4 years ago

<html>
  <head>
    <style type="text/css">
      pre {background-color:rgba(0,0,0,0.2); padding:10px;}
    </style>
    <script src="/socket.io/socket.io.js"></script>
    <script src="http://code.jquery.com/jquery.js"></script>
    
    <script>
    $(function() {
      var socket = io.connect();
      var $pre = $('pre');
      
      socket.on('this', function (data) {
        
        $pre.text( $pre.text() + JSON.stringify(data) + '\n' );
        socket.emit('private message', 'Runnable', 'Hi!');
      });
    });
    </script>
    
  </head>
  <body>
    <h1>socket.io example</h1>
    <pre>..output here..
      
    </pre>
  </body>
<html>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).