<!DOCTYPE html>
|
<html lang="en">
|
|
<head>
|
<meta charset="utf-8">
|
|
</head>
|
|
<body>
|
<div>
|
<input style="width: max-content;" id="input_init" type="text">
|
<input type="button" value="初始化" onclick="Init()">
|
</div>
|
<div>
|
<input id="input_text" type="text">
|
<input type="button" value="发送" onclick="Send()">
|
</div>
|
<script type="text/javascript">
|
//高拍仪主服务指令控制地址
|
var url = "ws://192.168.1.2:25014/";
|
var ws_test;
|
if ('WebSocket' in window) {
|
ws_test = new WebSocket(url);
|
}
|
else if ('MozWebSocket' in window) {
|
ws_test = new MozWebSocket(url);
|
}
|
else {
|
alert("浏览器不支持WebSocket");
|
}
|
ws_test.onopen = function (evt) {
|
console.log("Connection open ...");
|
//ws.send("Hello WebSockets!");
|
};
|
|
ws_test.onmessage = function (evt) {
|
console.log(evt.data);
|
//ws.close();
|
};
|
|
ws_test.onclose = function (evt) {
|
console.log("Connection closed.");
|
};
|
function Init() {
|
var str = document.getElementById('input_init');
|
console.log(str.value);
|
ws_test.send(str.value);
|
}
|
function Send() {
|
var str = document.getElementById('input_text');
|
console.log(str.value);
|
ws_test.send(str.value);
|
}
|
</script>
|
</body>
|
|
</html>
|