>[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
