微调ws库的使用方法
This commit is contained in:
@@ -17,7 +17,7 @@ local socket = require "socket"
|
|||||||
local band, bor, bxor = bit.band, bit.bor, bit.bxor
|
local band, bor, bxor = bit.band, bit.bor, bit.bxor
|
||||||
local shl, shr = bit.lshift, bit.rshift
|
local shl, shr = bit.lshift, bit.rshift
|
||||||
|
|
||||||
OPCODES = {
|
local OPCODES = {
|
||||||
CONTINUE = 0,
|
CONTINUE = 0,
|
||||||
TEXT = 1,
|
TEXT = 1,
|
||||||
BINARY = 2,
|
BINARY = 2,
|
||||||
@@ -86,14 +86,8 @@ local function _send(SOCK, opcode, message)
|
|||||||
-- debug_print("[encode] end")
|
-- debug_print("[encode] end")
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M:send(message, type)
|
function _M:send(type, message)
|
||||||
local tempType = OPCODES.BINARY
|
_send(self.socket, OPCODES[type or "BINARY"] or OPCODES.BINARY, message)
|
||||||
for _, opcode in pairs(_M.OPCODES) do
|
|
||||||
if type == opcode then
|
|
||||||
tempType = type
|
|
||||||
end
|
|
||||||
end
|
|
||||||
_send(self.socket, tempType, message)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M:read()
|
function _M:read()
|
||||||
@@ -125,7 +119,7 @@ function _M:read()
|
|||||||
|
|
||||||
-- data
|
-- data
|
||||||
res = SOCK:receive(length)
|
res = SOCK:receive(length)
|
||||||
local closeCode = nil
|
local closeCode
|
||||||
if OPCODE == OPCODES.PING then
|
if OPCODE == OPCODES.PING then
|
||||||
self:pong(res)
|
self:pong(res)
|
||||||
elseif OPCODE == OPCODES.CLOSE then
|
elseif OPCODE == OPCODES.CLOSE then
|
||||||
|
|||||||
Reference in New Issue
Block a user