Advertisement
Guest User

SocketConnectTest.html

a guest
Oct 26th, 2011
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript" >
  5.  
  6. var websocket;
  7. var url = "ws://localhost:1234";
  8.  
  9. function init(){
  10. try{
  11. websocket = new MozWebSocket(url, "chat");
  12. }catch(e){
  13. websocket = new WebSocket(url, "char");
  14. }
  15.  
  16. websocket.onopen = function(evt) { onOpen(evt) };
  17. websocket.onclose = function(evt) { onClose(evt) };
  18. websocket.onmessage = function(evt) { onMessage(evt) };
  19. websocket.onerror = function(evt) { onError(evt) };
  20. }
  21.  
  22. var count = 0;
  23. function loop(){
  24. var message = "lala\n";
  25. websocket.send(message);
  26. count++;
  27.  
  28. setTimeout(loop, 500);
  29. }
  30.  
  31. function onOpen(event){
  32. alert("Socket has been opened!" + ('5' + 3) + ('5' - 3));
  33.  
  34. loop();
  35. }
  36.  
  37. function onMessage(evt){
  38. alert(evt);
  39. }
  40.  
  41. function onClose(event){
  42. alert("socket closed");
  43. }
  44.  
  45. function onError(event){
  46. alert(event.data);
  47. }
  48.  
  49. window.addEventListener("load", init, false);
  50.  
  51.  
  52. </script>
  53.  
  54. </head>
  55. <body>
  56.  
  57.  
  58.  
  59. </body>
  60. </html>
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement