Advertisement
codeplanner

XSockets Close From Client

Mar 20th, 2013
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title></title>
  5.     <script src="Scripts/jquery.js"></script>
  6.     <script src="Scripts/jXSockets.js"></script>
  7.     <script src="Scripts/jXSockets.fallback.js"></script>
  8.    
  9.     <script>
  10.         var ws = null;
  11.         $(function() {
  12.             //See http://pastebin.com/HEkdy9nL for C# code called
  13.             ws = new XSockets.WebSocket('ws://127.0.0.1:4502/Test');          
  14.  
  15.             ws.bind(XSockets.Events.close, function () {
  16.                 console.log('CLOSED');
  17.             });
  18.  
  19.             ws.bind(XSockets.Events.open, function () {
  20.                 console.log('OPEN');
  21.             });
  22.  
  23.             $('#hardkill').bind('click', function(e) {
  24.                 e.preventDefault();
  25.                 ws.close();
  26.             });
  27.            
  28.             $('#softkill').bind('click', function (e) {
  29.                 e.preventDefault();
  30.                 ws.trigger('terminate', {});
  31.             });
  32.         });
  33.  
  34.     </script>
  35. </head>
  36. <body>
  37.     <button id="hardkill">Close From Client</button>
  38.     <button id="softkill">Close By Calling Server From Client</button>
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement