Skip to content

Commit b364dfd

Browse files
committed
修复空消息问题
1 parent ca76842 commit b364dfd

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end
2828
* `client.onopen = function()`
2929
* `client.onmessage = function(message: string)`
3030
* `client.onerror = function(error: string)`
31-
* `client.onclose = function()`
31+
* `client.onclose = function(code: int, reason: string)`
3232
* `client.status -> int`
3333
* `client:send(message: string)`
3434
* `client:close()`

main.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ client.onopen = function()
66
client:send("hello from love2d")
77
client:close()
88
end
9-
client.onclose = function(code, message)
10-
print("closecode: "..code..", reason: "..message)
9+
client.onclose = function(code, reason)
10+
print("closecode: "..code..", reason: "..reason)
1111
end
1212

1313
function love.update()

websocket.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ local function read(ws)
137137
local b = {res:byte(1, 8)}
138138
length = shl(b[5], 24) + shl(b[6], 16) + shl(b[7], 8) + b[8]
139139
end
140+
if length==0 then return "", head, nil end
140141
res, err, part = sock:receive(length)
141142
if part then
142143
-- incomplete frame
@@ -201,7 +202,7 @@ function _M:update()
201202
local opcode = band(head, 0x0f)
202203
local fin = band(head, 0x80)==0x80
203204
if opcode==OPCODE.CLOSE then
204-
if res then
205+
if res~="" then
205206
local code = shl(res:byte(1), 8) + res:byte(2)
206207
self.onclose(code, res:sub(3))
207208
else

0 commit comments

Comments
 (0)