Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 54 lines (51 sloc) 2.15 KB
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WebSockets test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
function debug(str) {
$("#debug").append("<p>"+str+"<p>");
}
// WebSocket needs to be set to IP of arduino.
try {
window.console.log("Setting up socket");
//ws = new WebSocket("ws://109.228.139.253:8383/");
ws = new WebSocket("ws://10.0.1.83:8383/");
ws.onmessage = function(evt) {
window.console.log(evt.data);
$("#msg").append("<p>"+evt.data+"<p>");
};
ws.onerror = function(evt) {
window.console.log(evt.data);
$("#msg").append("<p> ERROR: "+evt.data+"<p>");
};
ws.onclose = function() {
window.console.log("onclose called");
debug("socket closed");
};
ws.onopen = function() {
window.console.log("onopen called");
debug("connected...");
ws.send("Hello, Ardunio");
};
} catch(exception) {
window.console.log('<p>Error'+exception);
}
});
$(document).mousedown(function() {
ws.send("0");
});
$(document).mouseup(function() {
ws.send("1");
});
</script>
</head>
<body>
<div id="debug"></div>
<div id="msg"></div>
</body>
</html>