赞
踩
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>go测试socket</title>
</head>
<body>
<script type="text/javascript">
var sock = null;
//服务器的地址
var wsuri = "ws://10.7.7.198:8081/websocket";
window.onload = function() {
console.log("onload");
sock = new WebSocket(wsuri);
sock.onopen = function() {
//成功连接到服务器
console.log("connected to " + wsuri);
}
sock.onclose = function(e) {
console.log("connection closed (" + e.code + ")");
}
sock.onmessage = function(e) {
//服务器发送通知
//开始处理
console.log("message received: " + e.data);
}
};
function send() {
var msg = document.getElementById('message').value;
sock.send(msg);
};
</script>
<h1>WebSocket Echo Test</h1>
<form>
<p>
Message: <input id="message" type="text" value="Hello, world!">
</p>
</form>
<button onclick="send();">Send Message</button>
</body>
</html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。