This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8c0be0
commit ef90d92
Showing
2 changed files
with
6 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,3 @@ | ||
= Feed Communications Server-Side WAR | ||
|
||
You can use the following simple .html file to send messages via WebSockets to the server-side. | ||
|
||
[source,html] | ||
---- | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>WebSockets Client</title> | ||
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | ||
</head> | ||
<body> | ||
Enter text to send to the websocket server: | ||
<div id="send"> | ||
<input type="text" id="data" size="100"/><br> | ||
<input type="button" id="sendtext" value="send text"/> | ||
</div> | ||
<div id="output"></div> | ||
</body> | ||
</html> | ||
<script> | ||
jQuery(function($){ | ||
if (!("WebSocket" in window)) { | ||
alert("Your browser does not support web sockets"); | ||
}else{ | ||
setup(); | ||
} | ||
function setup(){ | ||
// Note: You have to change the host var | ||
// if your client runs on a different machine than the websocket server | ||
var host = "ws://localhost:8080/hawkular/feed-comm/123-456"; | ||
var socket = new WebSocket(host); | ||
//console.log("socket status: " + socket.readyState); | ||
var $txt = $("#data"); | ||
var $btnSend = $("#sendtext"); | ||
$txt.focus(); | ||
// event handlers for UI | ||
$btnSend.on('click',function(){ | ||
var text = $txt.val(); | ||
if(text == ""){ | ||
return; | ||
} | ||
socket.send(text); | ||
$txt.val(""); | ||
}); | ||
$txt.keypress(function(evt){ | ||
if(evt.which == 13){ | ||
$btnSend.click(); | ||
} | ||
}); | ||
// event handlers for websocket | ||
if(socket){ | ||
socket.onopen = function(){ | ||
//alert("connection opened...."); | ||
} | ||
socket.onmessage = function(msg){ | ||
showServerResponse(msg.data); | ||
} | ||
socket.onclose = function(){ | ||
//alert("connection closed...."); | ||
showServerResponse("The connection has been closed."); | ||
} | ||
}else{ | ||
console.log("invalid socket"); | ||
} | ||
function showServerResponse(txt){ | ||
var p = document.createElement('p'); | ||
p.innerHTML = txt; | ||
document.getElementById('output').appendChild(p); | ||
} | ||
} | ||
}); | ||
</script> | ||
---- | ||
You can use websocket-test-client.html to send messages via WebSockets to the server-side. It can mimic a UI client or a feed. |
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