>[info] 客户端执行代码连接websocket
>[danger]重点:此处前后端的心跳包都是被注释掉了的,即章节八的关键代码是需要注释掉的,不然会有问题,前端一小会就被踢下线了
在线测试地址: http://www.easyswoole.com/wstool.html
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>
<body>
<script>
ws = new WebSocket("ws://123.56.71.69:1234");
ws.onopen = function() {
console.log("连接成功");
var uid = '{"id":"uid2"}';
ws.send(uid);
console.log("给服务端发送一个Json字符串:"+uid);
};
ws.onmessage = function(e) {
console.log("收到服务端的消息:" + e.data);
};
</script>
</body>
</html>
```
### 打开页面,按F12打开控制台查看console
![](https://img.kancloud.cn/fa/3f/fa3fbe3c56174fbe9f04404e46693bfe_1087x228.png)