使用php 5.6 + swoole 1.7.19开发的聊天室。
php serve.php [-d]
[-d] 后台作为守护进程运行
php client.php -u hsinlu -p hsinlu [-r]
-u 用户名
-p 密码
[-r] 是否接受客户端指令,如果传递此参数将只接收服务端发来的数据
list
messages
// 发送公共消息
chat::{content}
// 发送频道消息
chat:channel={channel}:{content}
// 发送私聊消息
chat:fd={fd}:{content}
所有消息传递均采用json格式
["login",{"username":"hsinlu","password":"hsinlu"}]
目前服务端未做完整的用户验证,username与password一致即可登录。
// 登录成功
["login",{"success":true}]
// 登录失败
["login",{"errors":["用户名和密码不正确。"]}]
["join",{"fd":4,"username":"hsinlu"}]
["leave",{"fd":4,"username":"hsinlu"}]
["list"]
["list",[{"fd":3,"username":"si","channel":"public","is_online":1},{"fd":4,"username":"hsinlu","channel":"public","is_online":1}]]
["messages"]
["messages",[{"fd":1,"from_fd":2,"content":"hello","channel":"whisper","time":"1443884147","is_readed":0},{"fd":1,"from_fd":2,"content":"hello si","channel":"whisper","time":"1443884264","is_readed":0}]]
// 公共频道
["chat",{"content":"hello","id":"2b1dc0c605d45cee8887e07e8188795e"}]
// 指定频道
["chat",{"to_channel":"public","content":"hello","id":"2b1dc0c605d45cee8887e07e8188795e"}]
// 私聊
["chat",{"to_fd":"1","content":"hello si","id":"7a1c7714b34897fac377fb1213eab409"}]
id为客户端生成的消息唯一标识
["chat",{"from_fd":2,"from_username":"hsinlu","content":"hello"}]
["chat",{"success":true,"id":"2b1dc0c605d45cee8887e07e8188795e"}]
id为客户端发送的消息唯一标识,服务端回复指定的id的消息是否发送成功。