11local debugPrint = false
22
3- local confCHN ,sendCHN ,readCHN
3+ local zPath , confCHN ,sendCHN ,readCHN = ...
44
55local connTimeout ,pongTimeout = 16 ,2.6
66local sleepInterval ,pingInterval = 6 ,0.26
@@ -14,9 +14,9 @@ local CHN_push,CHN_pop,CHN_peek=confCHN.push,confCHN.pop,confCHN.peek
1414
1515local SOCK = require ' socket' .tcp ()
1616--- @type Zenitha.Json
17- local JSON = require (( ... ) .. ' json' )
17+ local JSON = require (zPath .. ' json' )
1818
19- do -- Connect
19+ do -- Connect
2020 local conf = CHN_demand (confCHN )
2121 local host = conf .host
2222 local port = conf .port
@@ -38,7 +38,7 @@ do-- Connect
3838 ' Connection: Upgrade\r\n ' ..
3939 ' Upgrade: websocket\r\n ' ..
4040 ' Sec-WebSocket-Version: 13\r\n ' ..
41- ' Sec-WebSocket-Key: osT3F7mvlojIvf3/8uIsJQ==\r\n ' .. -- secKey
41+ ' Sec-WebSocket-Key: osT3F7mvlojIvf3/8uIsJQ==\r\n ' .. -- secKey
4242 headers ..
4343 ' \r\n '
4444 if debugPrint then
151151local readThread = coroutine.wrap (function ()
152152 local res ,err
153153 local op ,fin
154- local lBuffer = " " -- Long multi-pack buffer
154+ local lBuffer = " " -- Long multi-pack buffer
155155 while true do
156156 -- Byte 0-1
157157 res ,err = _receive (SOCK ,2 )
@@ -177,22 +177,22 @@ local readThread=coroutine.wrap(function()
177177 assert (res ,err )
178178
179179 -- React
180- if op == 8 then -- 8=close
181- CHN_push (readCHN ,8 )-- close
180+ if op == 8 then -- 8=close
181+ CHN_push (readCHN ,8 ) -- close
182182 if type (res )== ' string' then
183- CHN_push (readCHN ,res :sub (3 ))-- [Warning] 2 bytes close code at start so :sub(3)
183+ CHN_push (readCHN ,res :sub (3 )) -- [Warning] 2 bytes close code at start so :sub(3)
184184 else
185185 CHN_push (readCHN ," WS closed" )
186186 end
187187 error (" Server Close" )
188- elseif op == 0 then -- 0=continue
188+ elseif op == 0 then -- 0=continue
189189 lBuffer = lBuffer .. res
190190 if fin then
191191 CHN_push (readCHN ,lBuffer )
192192 if debugPrint then print (' mMes<' ,lBuffer ) end
193193 lBuffer = " "
194194 end
195- elseif op == 9 then -- 9=ping
195+ elseif op == 9 then -- 9=ping
196196 _send (10 ,res )
197197 else
198198 CHN_push (readCHN ,op )
210210
211211local suc ,err
212212
213- while true do -- Running
213+ while true do -- Running
214214 while CHN_peek (confCHN ) do
215215 local c = CHN_pop (confCHN )
216216 local n = c [1 ]
@@ -239,6 +239,6 @@ while true do-- Running
239239end
240240
241241SOCK :close ()
242- CHN_push (readCHN ,8 )-- close
242+ CHN_push (readCHN ,8 ) -- close
243243CHN_push (readCHN ,err or " Disconnected" )
244244error ()
0 commit comments