封闭连接
封闭连接分为两种:办事端提议封闭和客户端主动封闭。
办事端跟客户端的处理根本一致,以办事端为例:
办事端提议封闭的时刻,会客户端发送一个封闭帧,客户端在接收到帧的时刻经由过程解析出帧的opcode来断定是否是封闭帧,然后同样向办事端再发送一个封闭帧作为回应。
- if (op_code == OP_CLOSE) {
- int status_code;
- char *reason;
- char *status_code_buf = (char *)&status_code;
- status_code_buf[0] = payload[1];
- status_code_buf[1] = payload[0];
- reason = payload + 2;
- if (ws->state != WS_STATE_CLOSED) {
- /**
- * should send response to remote server
- */
- ws_send(ws, NULL, 0, OP_CLOSE | FLAG_FIN);
- ws->state = WS_STATE_CLOSED;
- }
推荐阅读
应用redis-6379为主机,其余两台为大年夜机应用 docker exec -ti 容器ID /bin/bash 分别进入三个Redis容器进入容器后,应用 redis-cli 敕令,连接redis办事端连接办过后,应用 info replication 查看当前机械的角色未>>>详细阅读
本文标题:WebSocket实现原理
地址:http://www.17bianji.com/lsqh/36156.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示