ClassServerSentEvents
Represents a Server-Sent Events (SSE) tunnel that allows bidirectional communication between a client and server. This class handles the reception of SSE messages from the server and forwards them to the client. It also manages the lifecycle of the tunnel, including opening, closing, and maintaining the connection.
Definition
Namespace:Fiddler
Assembly:FiddlerCore.dll
Syntax:
public class ServerSentEvents : BaseTunnel, ITunnel
Inheritance: objectBaseTunnelServerSentEvents
Implements:
Inherited Members
Properties
EgressByteCount
Returns number of bytes sent from the Client to the Server on this tunnel. Since this is a Server-Sent Events tunnel, this value is typically 0, as the client does not send data to the server in the same way as in a WebSocket tunnel.
Declaration
public override long EgressByteCount { get; protected set; }
Property Value
Overrides
IngressByteCount
Returns number of bytes sent from the Server to the Client on this tunnel. This property is used to track the amount of data sent from the server to the client during the lifetime of the tunnel.
Declaration
public override long IngressByteCount { get; protected set; }
Property Value
Overrides
Methods
CreateTunnel(Session, MemoryStream, int)
Creates a new ServerSentEvents tunnel for the specified session. This method initializes the tunnel and starts it on a new background thread.
Declaration
public static void CreateTunnel(Session session, MemoryStream responseStream, int iEntityBodyOffset)
Parameters
session
The session for which the tunnel is being created.
responseStream
The stream containing the response data to be tunneled.
iEntityBodyOffset
The offset in the response stream where the entity body starts.
Exceptions
Thrown when the session is null.
Thrown when a tunnel already exists for the session.
Remarks
This method assumes ownership of the client and server pipes to prevent the session from closing or pooling them. It extracts the initial message from the response stream and starts the tunnel on a new thread. The tunnel will handle the reception of SSE messages and forward them to the client.
DoCloseTunnelAsync()
Closes the tunnel and releases resources associated with it. This method is called when the tunnel is no longer needed, either due to completion of the session or an error.
StartReceive(byte[])
Called when we have received data from the remote host. Incoming data will immediately be forwarded to the local client.