diff --git a/example/network_websocket.lua b/example/network_websocket.lua index e7e42583..c65b5c9a 100644 --- a/example/network_websocket.lua +++ b/example/network_websocket.lua @@ -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) diff --git a/lualib/moon/http/websocket.lua b/lualib/moon/http/websocket.lua index f3725288..b5093b3a 100644 --- a/lualib/moon/http/websocket.lua +++ b/lualib/moon/http/websocket.lua @@ -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)