-
Notifications
You must be signed in to change notification settings - Fork 503
Home
客户端(浏览器, 手机app等)连接到公共端口, 接收服务器的推送. 默认的公共端口是 8100
.
请求:
Long-polling
http://127.0.0.1:8100/poll?cname=$channel&seq=$next_seq&token=$token
Forever iframe
http://127.0.0.1:8100/iframe?cname=$channel&seq=$next_seq&token=$token
Streaming(HTTP endless chunk)
http://127.0.0.1:8100/stream?cname=$channel&seq=$next_seq&token=$token
Streaming 方式适合手机 App 使用, 见 iComet for iOS App
Parameters:
- cname: 频道的名字.
- token: 由
/sign
接口返回的 token, 是访问频道的安全令牌. 当开启了auth: token
配置项时, 客户端必须拿到 token 才能连接上指定的频道, 避免身份冒用. - seq: 客户端想接收的下一条消息的序号, 从
1
开始.
响应:
如果HTTP响应的状态码不是 200
, 一般是 iComet server 挂了.
Long-polling
icomet_cb([{type: "data", cname: "a", seq: "1", content: "a"}]);
icomet_cb({type: "data", cname: "a", seq: "1", content: "a"});
长连接模式每收到一条消息, HTTP请求就完成了. 当有老的消息时, 返回的是前一种, 多条(或者仅一条)老消息被放在一个数组里. 如果是新消息, 返回的是后一种.
Forever iframe
<script>parent.icomet_cb({type: "data", cname: "a", seq: "0", content: "a"});</script>
每一条消息作为一个 HTTP chunk 返回.
Streaming(HTTP endless chunk)
{type: "data", cname: "a", seq: "1", content: "a"}
这种模式一般用于非网页模式的客户端, 如手机 app. 每一条消息作为一个 HTTP chunk, 只有消息本身的 json 文本, 不包含额外的文本.
Parameters:
- type: 消息类型
- data: 正常的消息.
- next_seq: 当客户端收到这种类型的消息, 必须重置其序号.
- noop: 心跳消息.
- 429: Error message, too many channels/subscribers.
- 401: Error message, token error.
管理端口是内部端口, 被内部的系统调用. 例如, 创建频道, 推送消息, 关闭频道, 等等. 默认的配置禁止客户端访问管理端口. 默认的管理端口是 8000
l
请求:
http://127.0.0.1:8000/sign?cname=$channel[&expires=60]
The created channel will be waiting for 60 seconds to expire before any subscriber arrives.
响应:
{type: "sign", cname: "a", seq: 0, token: "36289dcb55bc35aa6893f7557b7fc28c", expires: 30, sub_timeout: 10}
支持 HTTP GET/POST.
请求:
http://127.0.0.1:8000/push?cname=$channel&content=$content
响应:
{type: "ok"}
向某个频道推送一条消息.
发送一条广播消息
请求:
http://127.0.0.1:8000/broadcast?content=12345
响应:
销毁通道.
请求:
http://127.0.0.1:8000/close?cname=$channel
响应:
清除通道的消息.
请求:
http://127.0.0.1:8000/clear?cname=$channel
响应:
获取 comet-server 或者某个频道的信息.
请求:
http://127.0.0.1:8000/info
- cname: 频道的名字(可选)
响应:
如果不指定 cname:
{"version": "0.2.2.1", "channels": 0, "subscribers": 0}
如果指定 cname:
{"cname": "a", "subscribers": 0}
检查某个频道是否存在, 且有订阅者连接.
请求:
http://127.0.0.1:8000/check?cname=$channel
响应:
{"a": 1}
{}
Subscriber to comet-server's channel creation and deletion events, events are received as HTTP chunks.
请求:
http://127.0.0.1:8000/psub
响应:
1 channel
0 channel