-
-
Save divyen/a9409a82d2379d52e9af to your computer and use it in GitHub Desktop.
Alchemy WebSocket Client - HTML5
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" | |
/> | |
<title>Alchemy Client</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
function openConnection() { | |
// uses global 'conn' object | |
if (conn.readyState === undefined || conn.readyState > 1) { | |
conn = new WebSocket('ws://localhost:8100'); | |
conn.onopen = function () { | |
conn.send("Connection Established Confirmation"); | |
}; | |
conn.onmessage = function (event) { | |
document.getElementById("content").innerHTML = event.data; | |
}; | |
conn.onerror = function (event) { | |
alert("Web Socket Error"); | |
}; | |
conn.onclose = function (event) { | |
alert("Web Socket Closed"); | |
}; | |
} | |
} | |
$(document).ready(function () { | |
conn = {}, window.WebSocket = window.WebSocket || window.MozWebSocket; | |
openConnection(); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="content"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment