diff --git a/vlib/net/websocket/ws.v b/vlib/net/websocket/ws.v index efb4b14732..5517660ea2 100644 --- a/vlib/net/websocket/ws.v +++ b/vlib/net/websocket/ws.v @@ -590,6 +590,10 @@ pub fn (mut ws Client) read() int { return -1 } +pub fn (mut ws Client) send_pong() int { + return ws.send_control_frame(.pong, 'PONG', []) +} + fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []byte) int { mut bytes_written := -1 if ws.socket.sockfd <= 0 { @@ -650,4 +654,4 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b return bytes_written } } -} +} \ No newline at end of file diff --git a/vlib/net/websocket/ws_test.v b/vlib/net/websocket/ws_test.v index 10568922d6..dde0daca02 100644 --- a/vlib/net/websocket/ws_test.v +++ b/vlib/net/websocket/ws_test.v @@ -41,7 +41,9 @@ fn ws_test(uri string) { } } -fn on_open(mut test Test, x voidptr, ws &websocket.Client) { +fn on_open(mut test Test, x voidptr, mut ws &websocket.Client) { + // Send PONG only for testing porposes + ws.send_pong() println('websocket opened.') test.connected = true }