1.环境:
-
php7.0
-
swoole(异步网络框架)
-
nginx服务器
2.项目
-
源码(页面:index.html,后端:ws_chat.php):https://gitee.com/zouchengxin/swoole_chat
-
体验地址(可以多开几个浏览器窗口测试):http://39.106.207.193:8080/swoole/swoole_chat
-
实现的功能:
-
群发消息
-
一对一发送消息
-
发送文件,图片(加入房间,创建房间,发送语音,视频通话暂未完成)
-
本项目对用户的输入没有进行处理,所以可以输入javascript代码,所有客户端都会直接执行代码.
<script> alert("helloword");//弹出对话框</script><script> window.navigator.vibrate(200);//对于手机设备振动200ms</script><script>Notification.requestPermission( function(status) { console.log(status); // 仅当值为 "granted" 时显示通知 if(status=='granted'){ var n = new Notification("title", {body: "notification body"}); // 显示通知 n.onshow = function () { setTimeout(n.close.bind(n), 5000); } }});</script>12345678910111213141516171819
也没有用数据库存储聊天数据,所以每次进入聊天室都只会接收显示之后连接用户的消息