swoole,websocket简易聊天室
swoole,php扩展
websocket,H5新特性,全双工通讯的协议。
背景: 一个小项目的群聊,在这之前使用过ajax轮循,但是无法达到效果,所以使用了websocket.
不说了 上代码。
看前台代码:
前台部分:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title id="myTitle">IM</title>
</head>
<style>
body {
background-color:gray;
}
#myname {
width:120px;
height:30px;
}
.setUserName {
width:80px;
height:30px;
}
#msg{
margin:80px 300px;
width:450px;
height:200px;
background-color:white;
}
.show_send{
margin:0px 300px;
}
#text{
width:200px;
height:50px;
}
.send_button{
width:80px;
height:30px;
}
</style>
<body>
<h1>swoole-websocket 及时通讯demo</h1>
<!--发送信息-->
<div id="send_msg" class="main box-shadow" style="display:none;">
<div id="msg"></div>