Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. Method for connect to server please specify your IP in Websocket constructur
  2.  
  3. function WebSocketTest()
  4. {
  5. if ("WebSocket" in window)
  6. {
  7. alert("WebSocket is supported by your Browser!");
  8.  
  9. // Let us open a web socket
  10. *var ws = new WebSocket("ws://www.google.co.in/");*
  11.  
  12. ws.onopen = function()
  13. {
  14. // Web Socket is connected, send data using send()
  15. ws.send("{"sessionId":"1","message":"hi google"}");
  16. alert("Message is sent...");
  17. };
  18.  
  19. ws.onmessage = function (evt)
  20. {
  21. var received_msg = evt.data;
  22. alert("Message is received..."+received_msg);
  23. };
  24.  
  25. ws.onclose = function()
  26. {
  27. // websocket is closed.
  28. alert("Connection is closed...");
  29. };
  30. }
  31.  
  32. else
  33. {
  34. // The browser doesn't support WebSocket
  35. alert("WebSocket NOT supported by your Browser!");
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement