ws库再升级
This commit is contained in:
@@ -93,7 +93,7 @@ do--Connect
|
|||||||
else
|
else
|
||||||
readCHN:push(err)
|
readCHN:push(err)
|
||||||
end
|
end
|
||||||
SOCK:settimeout(0)
|
SOCK:settimeout(6.26)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -125,31 +125,54 @@ while true do--Running
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Receive data
|
--Receive data
|
||||||
res=SOCK:receive(length)
|
res=""
|
||||||
|
while length>0 do
|
||||||
|
local t=SOCK:receive(length)
|
||||||
|
if t then
|
||||||
|
res=res..t
|
||||||
|
length=length-#t
|
||||||
|
else--Time out!
|
||||||
|
res=false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--React
|
--React
|
||||||
if op==8 then--8=close
|
if res then
|
||||||
readCHN:push(op)
|
if op==8 then--8=close
|
||||||
SOCK:close()
|
readCHN:push(op)
|
||||||
if type(res)=="string"then
|
SOCK:close()
|
||||||
local reason=JSON.decode(res)
|
if type(res)=="string"then
|
||||||
readCHN:push(reason and reason.message or"Server Error")
|
local reason=JSON.decode(res)
|
||||||
|
readCHN:push(reason and reason.message or"Server Error")
|
||||||
|
else
|
||||||
|
readCHN:push("Server Error")
|
||||||
|
end
|
||||||
|
elseif op==0 then--0=continue
|
||||||
|
buffer=buffer..res
|
||||||
|
if fin then
|
||||||
|
-- print("FIN=1 (c")
|
||||||
|
readCHN:push(buffer)
|
||||||
|
buffer=""
|
||||||
|
else
|
||||||
|
-- print("FIN=0 (c")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
readCHN:push("Server Error")
|
readCHN:push(op)
|
||||||
end
|
if fin then
|
||||||
elseif op==0 then
|
-- print("OP: "..op.."\tFIN=1")
|
||||||
buffer=buffer..res
|
readCHN:push(res)
|
||||||
if fin then
|
else
|
||||||
readCHN:push(buffer)
|
-- print("OP: "..op.."\tFIN=0")
|
||||||
buffer=""
|
buffer=res
|
||||||
|
-- print("START pack: "..res)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
readCHN:push(op)
|
--TIMEOUT
|
||||||
if fin then
|
SOCK:close()
|
||||||
readCHN:push(res)
|
readCHN:push(8)
|
||||||
else
|
readCHN:push("WS time out")
|
||||||
buffer=res
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user