|
|
@ -4,35 +4,30 @@ |
|
|
|
<script language="javascript" type="text/javascript"> |
|
|
|
<script language="javascript" type="text/javascript"> |
|
|
|
// <!--var wsUri = "ws://172.10.10.9/echo/"; --> |
|
|
|
// <!--var wsUri = "ws://172.10.10.9/echo/"; --> |
|
|
|
var ws = "ws://echo.websocket.org/"; |
|
|
|
var ws = "ws://echo.websocket.org/"; |
|
|
|
// var output; |
|
|
|
var output; |
|
|
|
// function init() { |
|
|
|
function init() { |
|
|
|
// output = document.getElementById("output"); testWebSocket(); } |
|
|
|
output = document.getElementById("output"); testWebSocket(); } |
|
|
|
// function testWebSocket() { |
|
|
|
function testWebSocket() { |
|
|
|
// websocket = new WebSocket(wsUri); |
|
|
|
websocket = new WebSocket(ws); |
|
|
|
// websocket.onopen = function(evt) { onOpen(evt) }; |
|
|
|
websocket.onopen = function(evt) { onOpen(evt) }; |
|
|
|
// websocket.onclose = function(evt) { onClose(evt) }; |
|
|
|
websocket.onclose = function(evt) { onClose(evt) }; |
|
|
|
// websocket.onmessage = function(evt) { onMessage(evt) }; |
|
|
|
websocket.onmessage = function(evt) { onMessage(evt) }; |
|
|
|
// websocket.onerror = function(evt) { onError(evt) }; } |
|
|
|
websocket.onerror = function(evt) { onError(evt) }; } |
|
|
|
// function onOpen(evt) { |
|
|
|
} |
|
|
|
// writeToScreen("CONNECTED"); doSend("WebSocket rocks sssssssssssssssssssssssssss"); } |
|
|
|
function onOpen(evt) { |
|
|
|
// function onClose(evt) { writeToScreen("DISCONNECTED"); } |
|
|
|
writeToScreen("CONNECTED"); doSend("WebSocket rocks sssssssssssssssssssssssssss"); } |
|
|
|
// function onMessage(evt) { |
|
|
|
function onClose(evt) { writeToScreen("DISCONNECTED"); } |
|
|
|
// writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>'); websocket.close(); } |
|
|
|
function onMessage(evt) { |
|
|
|
// function onError(evt) { writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); } |
|
|
|
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>'); websocket.close(); } |
|
|
|
// function doSend(message) { writeToScreen("SENT: " + message); websocket.send(message); } |
|
|
|
function onError(evt) { writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); } |
|
|
|
// function writeToScreen(message) { |
|
|
|
function doSend(message) { writeToScreen("SENT: " + message); websocket.send(message); } |
|
|
|
// var pre = document.createElement("p"); |
|
|
|
function writeToScreen(message) { |
|
|
|
// pre.style.wordWrap = "break-word"; |
|
|
|
var pre = document.createElement("p"); |
|
|
|
// pre.innerHTML = message; output.appendChild(pre); } |
|
|
|
pre.style.wordWrap = "break-word"; |
|
|
|
// |
|
|
|
pre.innerHTML = message; output.appendChild(pre); } |
|
|
|
// window.addEventListener("load", init, false); |
|
|
|
|
|
|
|
ws.onopen = function(){ws.send("Test!"); }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws.onmessage = function(evt){console.log(evt.data);ws.close();}; |
|
|
|
window.addEventListener("load", init, false); |
|
|
|
|
|
|
|
|
|
|
|
ws.onclose = function(evt){console.log("Test2!");}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws.onerror = function(evt){console.log("Test3!");}; |
|
|
|
|
|
|
|
</script> |
|
|
|
</script> |
|
|
|
<h2>WebSocket Test</h2> |
|
|
|
<h2>WebSocket Test</h2> |
|
|
|
<div id="output"></div> |
|
|
|
<div id="output"></div> |