#1 2026-04-30 14:06:39

ec
Member
Registered: 2023-08-24
Posts: 45

Feature Request: Include focPing/focPong in TOnWebSocketProtocolIncomi

Hi Arnaud and community,


I'm working on a mission-critical infrastructure using mORMot 2 asynchronous WebSockets and I've encountered a limitation regarding connection health monitoring.

Looking at TWebSocketProcess.ProcessLoopReceived in mormot.net.ws.core.pas, I noticed that fOnBeforeIncomingFrame (and consequently OnBeforeIncomingFrame) is only triggered for focText and focBinary opcodes:

case request.opcode of
  focPing:
    begin
      request.opcode := focPong;
      SendFrame(request);
    end;
  focPong:
    ; // nothing to do
  focText,
  focBinary:
    if Assigned(fProtocol) then
      if (not Assigned(fProtocol.fOnBeforeIncomingFrame)) or
         (not fProtocol.fOnBeforeIncomingFrame(self, request)) then
        fProtocol.ProcessIncomingFrame(self, request, '');

Was it intentional to exclude control frames (focPing / focPong) from the interceptor?

In high-availability systems, we need to monitor real-time health and latency without injecting application-level heartbeats (to keep the protocol clean). If focPing and focPong were passed to OnBeforeIncomingFrame, we could intercept them for auditing and metrics before the framework handles the automatic response.

Would you consider moving the fOnBeforeIncomingFrame check to the beginning of the ProcessLoopReceived procedure, or at least including these opcodes in the dispatcher?

Something like:

procedure TWebSocketProcess.ProcessLoopReceived(var request: TWebSocketFrame);
begin
  if Assigned(fProtocol.fOnBeforeIncomingFrame) then
    if fProtocol.fOnBeforeIncomingFrame(self, request) then
      exit; // Allow manual override or sniffing

  case request.opcode of
    // ... rest of the logic


Thank you for this amazing framework!

Offline

#2 2026-04-30 15:10:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,475
Website

Re: Feature Request: Include focPing/focPong in TOnWebSocketProtocolIncomi

Please try with
https://github.com/synopse/mORMot2/commit/8ece4a871

There is a new NotifyAllFrames boolean flag.

Offline

#3 2026-04-30 15:59:03

ec
Member
Registered: 2023-08-24
Posts: 45

Re: Feature Request: Include focPing/focPong in TOnWebSocketProtocolIncomi

Hi Arnaud,

Thank you very much for the quick fix!

This change is very helpful for monitoring connection health and latency in our infrastructure. I've already tested it and it works perfectly.

Offline

Board footer

Powered by FluxBB