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 SubEvent 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 SubMethods
Connect
Connects to SSE server.
vb
Public Function Connect(ByVal ServerUrl As String) As cSSEClientDisconnect
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
| Property | Type | Description |
|---|---|---|
Url | String | Current connection URL |
Connected | Boolean | Connection status |
Connecting | Boolean | Whether connecting |
AutoReconnect | Boolean | Enable auto reconnect (default True) |
ReconnectInterval | Long | Reconnect interval (ms, default 3000ms) |
MaxReconnectAttempts | Long | Max reconnect attempts (default 10) |
CurrentReconnectAttempts | Long | Current reconnect attempts |
LastReceivedEventId | String | Last received event ID |
CurrentReconnectDelay | Long | Current reconnect delay (ms) |
ServerReconnectInterval | Long | Server-specified reconnect interval |
Events
| Event | Description |
|---|---|
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