Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/javascript" >
- var websocket;
- var url = "ws://localhost:1234";
- function init(){
- try{
- websocket = new MozWebSocket(url, "chat");
- }catch(e){
- websocket = new WebSocket(url, "char");
- }
- websocket.onopen = function(evt) { onOpen(evt) };
- websocket.onclose = function(evt) { onClose(evt) };
- websocket.onmessage = function(evt) { onMessage(evt) };
- websocket.onerror = function(evt) { onError(evt) };
- }
- var count = 0;
- function loop(){
- var message = "lala\n";
- websocket.send(message);
- count++;
- setTimeout(loop, 500);
- }
- function onOpen(event){
- alert("Socket has been opened!" + ('5' + 3) + ('5' - 3));
- loop();
- }
- function onMessage(evt){
- alert(evt);
- }
- function onClose(event){
- alert("socket closed");
- }
- function onError(event){
- alert(event.data);
- }
- window.addEventListener("load", init, false);
- </script>
- </head>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement