From 74759e3e0dbca18d620d15093060ca5af68d2fcb Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sun, 14 Feb 2021 18:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83ws=E5=BA=93=E7=9A=84=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/websocket.lua | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Zframework/websocket.lua b/Zframework/websocket.lua index 930c6a9d..46fa8681 100644 --- a/Zframework/websocket.lua +++ b/Zframework/websocket.lua @@ -17,7 +17,7 @@ local socket = require "socket" local band, bor, bxor = bit.band, bit.bor, bit.bxor local shl, shr = bit.lshift, bit.rshift -OPCODES = { +local OPCODES = { CONTINUE = 0, TEXT = 1, BINARY = 2, @@ -86,14 +86,8 @@ local function _send(SOCK, opcode, message) -- debug_print("[encode] end") end -function _M:send(message, type) - local tempType = OPCODES.BINARY - for _, opcode in pairs(_M.OPCODES) do - if type == opcode then - tempType = type - end - end - _send(self.socket, tempType, message) +function _M:send(type, message) + _send(self.socket, OPCODES[type or "BINARY"] or OPCODES.BINARY, message) end function _M:read() @@ -125,7 +119,7 @@ function _M:read() -- data res = SOCK:receive(length) - local closeCode = nil + local closeCode if OPCODE == OPCODES.PING then self:pong(res) elseif OPCODE == OPCODES.CLOSE then