Java Reference
In-Depth Information
Examining the generated JavaScript code
The other file in the Echo WebSocket sample included with NetBeans is an HTML
file that contains embedded JavaScript used to communicate with the Java server
endpoint. Take a look at the following code:
<html>
<head>
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
</head>
<body>
<meta charset="utf-8">
<title>Web Socket JavaScript Echo Client</title>
<script language="javascript" type="text/javascript">
var wsUri = getRootUri() + "/websocket-echo/echo";
function getRootUri() {
return "ws://" + (document.location.hostname == "" ?
"localhost" :
document.location.hostname) + ":" +
(document.location.port == "" ? "8080" :
document.location.port);
}
function init() {
output = document.getElementById("output");
}
function send_echo() {
websocket = new WebSocket(wsUri);
websocket.onopen = function (evt) {
onOpen(evt)
};
websocket.onmessage = function (evt) {
onMessage(evt)
};
websocket.onerror = function (evt) {
onError(evt)
};
}
 
Search WWH ::




Custom Search