<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.kuang{text-align: center;margin-top:200px;}
#mess{text-align: left}
</style>
</head>
<body>
<input id="t1" type=text value="ls" onkeydown="KeyDown();"/>
<input type=button value="runShell" onclick="aa();">
<div id="mess"></div>
<script>
var mess = document.getElementById("mess");
if(window.WebSocket){
var ws = new WebSocket('ws://127.0.0.1:8002');
ws.onopen = function(e){
console.log("连接服务器成功");
ws.send("ls");
}
ws.onclose = function(e){
console.log("服务器关闭");
}
ws.onerror = function(){
console.log("连接出错");
}
ws.onmessage = function(e){
//mess.innerHTML = "连接成功"
var time = new Date();
mess.innerHTML+=(e.data+"<br>");
}
}
function aa(){
var t = document.getElementById("t1");
console.log(t.value);
ws.send(t.value,"ff");
}
function KeyDown()
{
if (event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
aa();
}
}
</script>
</body>
</html>