Skip to content

cSSEClient SSE Client Component

Introduction

cSSEClient is a Server-Sent Events (SSE) client implementation for receiving real-time push messages from server. Supports auto reconnect, event parsing, and connection state management.

Features

  • Auto reconnect mechanism
  • Real-time event receiving
  • Custom reconnect interval support
  • Last-Event-ID resumption support
  • Connection state management
  • Max reconnect attempts limit

Quick Start

Basic Usage

vb
Private WithEvents SSE As cSSEClient

Private Sub Form_Load()
    Set SSE = New cSSEClient
    
    ' Configure reconnect parameters
    SSE.AutoReconnect = True
    SSE.ReconnectInterval = 3000   ' 3 seconds
    SSE.MaxReconnectAttempts = 10
    
    ' Connect to SSE server
    Call SSE.Connect("https://api.example.com/events")
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call SSE.Disconnect()
    Set SSE = Nothing
End Sub

Event Handling

vb
' Connection established
Private Sub SSE_OnOpen()
    Debug.Print "SSE connection established"
End Sub

' Message received
Private Sub SSE_OnMessage(EventName As String, Data As String, Id As String)
    Debug.Print "Event: " & EventName
    Debug.Print "Data: " & Data
    Debug.Print "ID: " & Id
End Sub

' Error occurred
Private Sub SSE_OnError(Description As String, ErrorNumber As Long)
    Debug.Print "SSE error " & ErrorNumber & ": " & Description
End Sub

' Connection closed
Private Sub SSE_OnClose()
    Debug.Print "SSE connection closed"
End Sub

Methods

Connect

Connects to SSE server.

vb
Public Function Connect(ByVal ServerUrl As String) As cSSEClient

Disconnect

Disconnects SSE connection.

vb
Public Sub Disconnect()

EnableAutoReconnect

Enables auto reconnect.

vb
Public Sub EnableAutoReconnect()

DisableAutoReconnect

Disables auto reconnect.

vb
Public Sub DisableAutoReconnect()

ResetReconnectAttempts

Resets reconnect counter.

vb
Public Sub ResetReconnectAttempts()

Properties

PropertyTypeDescription
UrlStringCurrent connection URL
ConnectedBooleanConnection status
ConnectingBooleanWhether connecting
AutoReconnectBooleanEnable auto reconnect (default True)
ReconnectIntervalLongReconnect interval (ms, default 3000ms)
MaxReconnectAttemptsLongMax reconnect attempts (default 10)
CurrentReconnectAttemptsLongCurrent reconnect attempts
LastReceivedEventIdStringLast received event ID
CurrentReconnectDelayLongCurrent reconnect delay (ms)
ServerReconnectIntervalLongServer-specified reconnect interval

Events

EventDescription
OnOpen()Triggers when connection is established
OnMessage(EventName, Data, Id)Triggers when message received
OnError(Description, ErrorNumber)Triggers when error occurs
OnClose()Triggers when connection closes

Last Updated: 2026-05-17

VB6 and LOGO copyright of Microsoft Corporation