Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion async/websocket_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ let client_ez ?opcode ?(name = "websocket.client_ez") ?extra_headers ?heartbeat
Logs_async.debug ~src (fun m -> m "<- %a" Frame.pp fr) >>= fun () ->
match fr.opcode with
| Opcode.Ping ->
Pipe.write w @@ Frame.create ~opcode:Opcode.Pong () >>| fun () -> None
Pipe.write w @@ Frame.create ~opcode:Opcode.Pong () ~content:fr.content
>>| fun () -> None
| Opcode.Close ->
(* Immediately echo and pass this last message to the user *)
(if String.length fr.content >= 2 then
Expand Down
6 changes: 4 additions & 2 deletions core/websocket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,10 @@ module Make (IO : Cohttp.S.IO) = struct
t.read_frame () >>= fun fr ->
match fr.Frame.opcode with
| Frame.Opcode.Ping ->
send t @@ Frame.create ~opcode:Frame.Opcode.Pong () >>= fun () ->
return fr
(* Ping frames must be answered by pong frame with the same content. *)
send t @@
Frame.create ~opcode:Frame.Opcode.Pong ~content:fr.content ()
>>= fun () -> return fr
| Frame.Opcode.Close ->
(* Immediately echo and pass this last message to the user *)
(if String.length fr.Frame.content >= 2 then
Expand Down
4 changes: 2 additions & 2 deletions lwt/wscat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ let client uri =
let close_sent = ref false in
let rec react () =
Websocket_lwt_unix.read conn >>= function
| { Frame.opcode = Ping; _ } ->
write conn (Frame.create ~opcode:Pong ()) >>= react
| { Frame.opcode = Ping; content; _ } ->
write conn (Frame.create ~opcode:Pong ~content ()) >>= react
| { opcode = Close; content; _ } ->
(* Immediately echo and pass this last message to the user *)
(if !close_sent then Lwt.return_unit
Expand Down