Skip to content

Commit

Permalink
websocket server: send pong on ping
Browse files Browse the repository at this point in the history
Hopefully closes #1222.
  • Loading branch information
glacambre committed Oct 30, 2021
1 parent eb3abef commit 553c913
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lua/firenvim-websocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ local function encode_frame(data)
return header .. len .. data
end

local function pong_frame(decoded_frame)
-- 137: 10001010
-- Fin: 1
-- RSV{1,2,3}: 0
-- Opcode: 0xA (pong)
return string.char(138) .. decoded_frame.payload_length .. decoded_frame.payload_data
end

local function close_frame()
local frame = encode_frame("")
return string.char(136) .. string.sub(frame, 2)
Expand All @@ -149,4 +157,5 @@ return {
encode_frame = encode_frame,
opcodes = opcodes,
parse_headers = parse_headers,
pong_frame = pong_frame,
}
3 changes: 1 addition & 2 deletions lua/firenvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ local function connection_handler(server, sock, token)
current_payload = ""
end
elseif decoded_frame.opcode == websocket.opcodes.ping then
-- TODO: implement websocket.pong_frame
-- sock:write(websocket.pong_frame(decoded_frame))
sock:write(websocket.pong_frame(decoded_frame))
return
elseif decoded_frame.opcode == websocket.opcodes.close then
sock:write(websocket.close_frame(decoded_frame))
Expand Down

0 comments on commit 553c913

Please sign in to comment.