程序员

swoole

2018-05-31  本文已影响0人  云边一片海

服务端

/**

}

// 启动服务器
$server = new Server();
$server->index();

客户端

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
if ("WebSocket" in window)
{
console.log("您的浏览器支持 WebSocket!");
var ws = new WebSocket("ws://192.168.1.158:9501");
ws.onConnect = function(){
ws.send("链接");
};
ws.onopen = function() {
ws.send("AService");
};
ws.onmessage = function(evt){
var received_msg = evt.data;
console.log(received_msg);
};
ws.onclose = function() {
console.log("连接已关闭...");
};
}
else {
console.log("您的浏览器不支持 WebSocket!");
}
</script>
</head>
<body>
<h1 id="haha"></h1>
</body>
</html>

上一篇下一篇

猜你喜欢

热点阅读