Java Reference
In-Depth Information
...
<h:head>
<script type="text/javascript">
function acmeChatRelay()
{
alert("working");
if ("WebSocket" in window)
{
alert("WebSocket is supported by your Browser!");
// Let us open a web socket
var ws = new WebSocket("ws://localhost:8080/IntroToEE7/acmechat");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send("Message to send");
alert("Message is sent...");
};
ws.onmessage = function(evt)
{
var received_msg = evt.data;
alert("Message from server: " + received_msg);
};
ws.onclose = function()
{
// websocket is closed.
alert("Connection is closed...");
};
}
else
{
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
</script>
</h:head>
The following excerpt is taken from web/chapter09/acmeChatClient.xhtml , and it demonstrates how to invoke
the WebSocket call.
...
<h:body>
<ui:composition template="../layout/custom_template.xhtml">
<ui:define name="content">
<h:form>
<p>
Welcome to the Acme Chat Client. Use the
</p>
<h:inputTextarea id="messageText" cols="30" rows="10"/>
<br/>
 
Search WWH ::




Custom Search