Skip to content

Commit

Permalink
optimize websocket api
Browse files Browse the repository at this point in the history
  • Loading branch information
sniper00 committed Jul 18, 2024
1 parent dfc5d7f commit 549faf9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions example/network_websocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ websocket.on_accept(function(fd, request)
end)

websocket.wson("message",function(fd, msg)
print(moon.decode(msg, "Z"))

-- binary frame
-- socket.write(fd, msg)
-- websocket.write(fd, msg)

-- text frame
print(moon.decode(msg, "Z"))
websocket.write_text(fd, moon.decode(msg, "Z"))
end)

Expand Down
6 changes: 5 additions & 1 deletion lualib/moon/http/websocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ local socket_data_type = {
---| 'ping'
---| 'pong'

local websocket = {}
---@class websocket
---@field write fun(fd:integer, data:string|buffer_ptr|buffer_shr_ptr):boolean send binary data
local websocket = {
write = socket.write,
}

function websocket.close(fd)
socket.close(fd)
Expand Down

0 comments on commit 549faf9

Please sign in to comment.