From 8fdef2b7f5e083c87fefb16785f5f0f8fa65d878 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Wed, 17 Feb 2021 00:16:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E8=B0=83=E6=95=B4websocket=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/websocket.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Zframework/websocket.lua b/Zframework/websocket.lua index 37d453e2..fab6a2e8 100644 --- a/Zframework/websocket.lua +++ b/Zframework/websocket.lua @@ -27,8 +27,7 @@ function WS.new() return m end -local seckey="osT3F7mvlojIvf3/8uIsJQ==" -function WS:connect(server,path,head,body) +function WS:connect(server,path,body) local host,port=unpack(splitStr(server,":")) local SOCK=self.socket local res,err=SOCK:connect(host,port or 80) @@ -44,8 +43,7 @@ function WS:connect(server,path,head,body) "Content-Type: application/json\r\n".. "Content-Length: "..#body.."\r\n".. "Sec-WebSocket-Version: 13\r\n".. - "Sec-WebSocket-Key: "..seckey.."\r\n".. - (head or"").."\r\n".. + "Sec-WebSocket-Key: osT3F7mvlojIvf3/8uIsJQ==\r\n\r\n"..--secKey body ) repeat res=SOCK:receive("*l")until res=="" @@ -86,8 +84,8 @@ local OPcode={ ping=9, pong=10 } -function WS:send(message,type) - _send(self.socket,OPcode[type] or 2--[[binary]],message) +function WS:send(message,op) + _send(self.socket,OPcode[op] or 2--[[binary]],message) end function WS:read() @@ -115,7 +113,7 @@ function WS:read() res=SOCK:receive(length) local closeCode if OPCODE==9 then--ping - self:pong(res) + self:send(res,10--[[pong]]) elseif OPCODE==8 then--close closeCode=shl(res:byte(1),8)+res:byte(2) res=sub(res,3,-3)