0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Confirm Websocket pong frames are received by handlers

This commit is contained in:
Loïc Hoguin 2024-01-16 12:20:38 +01:00
parent 920adb9b82
commit 08a8d7b9e9
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
2 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,23 @@
%% This module sends an empty ping to the client and
%% waits for a pong before sending a text frame. It
%% is used to confirm server-initiated pings work.
-module(ws_ping_h).
-behavior(cowboy_websocket).
-export([init/2]).
-export([websocket_init/1]).
-export([websocket_handle/2]).
-export([websocket_info/2]).
init(Req, _) ->
{cowboy_websocket, Req, undefined}.
websocket_init(State) ->
{[{ping, <<>>}], State}.
websocket_handle(pong, State) ->
{[{text, <<"OK!!">>}], State}.
websocket_info(_, State) ->
{[], State}.