Created
October 18, 2013 18:58
-
-
Save incepttechnologies/7046388 to your computer and use it in GitHub Desktop.
WebSocket Client Side using javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var host = "ws://localhost:8080/JSFWebSockets/notification"; | |
var wSocket = new WebSocket(host); | |
var browserSupport = ("WebSocket" in window) ? true : false; | |
// called body onLoad() | |
function initializeReception() | |
{ | |
if (browserSupport) | |
{ | |
wSocket.onopen = function() | |
{ | |
//alert(" Web Socket is connected, sending data"); | |
wSocket.send("ping"); | |
}; | |
} | |
else | |
{ | |
// The browser doesn't support WebSocket | |
alert("WebSocket is NOT supported by your Browser!"); | |
} | |
} | |
// called when a message is received | |
wSocket.onmessage = function(event) | |
{ | |
var received_msg = event.data; | |
document.getElementById('headerForm:serverMsg').value = received_msg; | |
}; | |
// called when socket closes | |
wSocket.onclose = function() | |
{ | |
// websocket is closed. | |
//alert("Connection is closed..."); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment