Class
ServerSentEvents

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

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

cs-api-definition
public override long EgressByteCount { get; protected set; }

Property Value

long

Overrides BaseTunnel.EgressByteCount

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

cs-api-definition
public override long IngressByteCount { get; protected set; }

Property Value

long

Overrides BaseTunnel.IngressByteCount

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

cs-api-definition
public static void CreateTunnel(Session session, MemoryStream responseStream, int iEntityBodyOffset)

Parameters

session

Session

The session for which the tunnel is being created.

responseStream

MemoryStream

The stream containing the response data to be tunneled.

iEntityBodyOffset

int

The offset in the response stream where the entity body starts.

Exceptions

ArgumentNullException

Thrown when the session is null.

InvalidOperationException

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.

Declaration

cs-api-definition
public override Task DoCloseTunnelAsync()

Returns

Task

Overrides BaseTunnel.DoCloseTunnelAsync()

StartReceive(byte[])

Called when we have received data from the remote host. Incoming data will immediately be forwarded to the local client.

Declaration

cs-api-definition
protected Task StartReceive(byte[] initialData = null)

Parameters

initialData

byte[]

Returns

Task