Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.00 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.    <meta charset = "utf-8" />
  4.    <title>WebSocket Test</title>
  5.  
  6.    <script language = "javascript" type = "text/javascript">
  7.       var data = {
  8.          user: "Admin",
  9.          UserQuestionId: 70,
  10.          startTime: new Date().getTime()
  11.       }
  12.       var wsUri = "ws://192.168.1.27:8080";
  13.       var output;
  14.    
  15.       function init() {
  16.          output = document.getElementById("output");
  17.          testWebSocket();
  18.       }
  19.    
  20.       function testWebSocket() {
  21.          websocket = new WebSocket(wsUri);
  22.            
  23.          websocket.onopen = function(evt) {
  24.             onOpen(evt)
  25.          };
  26.       }
  27.    
  28.       function onOpen(evt) {
  29.          alert("CONNECTED");
  30.          websocket.send(JSON.stringify(data))
  31.       }
  32.    
  33.       window.addEventListener("load", init, false);
  34.    
  35.    function sendNoti() {
  36.       websocket.send(JSON.stringify(data))
  37.    }
  38.    </script>
  39.  
  40.    <h2>WebSocket Test</h2>
  41.    <div id = "output"></div>
  42.    <button onclick="sendNoti()"></button>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement