websocketd 在windows7 上使用python的办法
以下是python原代码。就是为了简单测试。
print("wuwuwuw")
然后开启websocketd服务器:
打开cmd输入:
然后服务器就跑起来了。
我们写个客户端脚本测试一下:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
websocket = new WebSocket("ws://localhost:8080");
websocket.onmessage = function (event)
{
alert(event.data);
}
websocket.onopen = function () {
console.log(this.readyState);
websocket.send("123");
websocket.send("456");
}
websocket.onerror = function (evt) {
console.log(evt);
}
websocket.onclose = function () {
alert("close");
}
console.log(websocket.readyState);
</script>
</body>
</html>
运行结果: