---
product: Chilkat
product_version: 11.7.0
language: tcl
language_label: Tcl
class: ServerSentEvent
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/tclServerSentEventRef.html
---
# Chilkat ServerSentEvent — Tcl — v11.7.0

> Chilkat 11.7.0 · language=tcl · class=ServerSentEvent
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/ServerSentEvent.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/tcl/guide.md`.

## Purpose

**Parse server-sent event text into event name, data, ID, and retry fields.**

`Chilkat.ServerSentEvent` is a small helper class for parsing Server-Sent Events formatted text. Given a multi-line event block, it extracts the `event` name, `data` payload, `id` value, and `retry` interval into simple read-only properties. It is useful when an application receives event-stream text and needs to work with the structured event fields instead of manually parsing the raw lines.

**Load event text**

Use `LoadEvent` to parse a complete multi-line Server-Sent Event block.

**Read event name**

Inspect `EventName` to determine the event type supplied by the server, if an `event:` field is present.

**Read event data**

Use `Data` to obtain the event payload, such as JSON text from a streaming API or real-time service.

**Track event IDs**

Read `LastEventId` when the event includes an `id:` field that identifies the event or stream position.

**Handle retry hints**

Use `Retry` to read the server-provided retry interval when a `retry:` field is included.

**Diagnostics**

Check `LastErrorText` if event text cannot be parsed or if a parsing result is unexpected.

**Relationship to `Chilkat.WebSocket`:** `ServerSentEvent` does not manage a WebSocket connection or parse WebSocket frames. Instead, it can be used after `Chilkat.WebSocket` receives a text message whose payload is formatted as a Server-Sent Event. Read the WebSocket text frame, pass the event text to `LoadEvent`, then use `EventName`, `Data`, `LastEventId`, and `Retry` to process the event.

**Common pattern:** Receive or otherwise obtain a complete Server-Sent Event text block, call `LoadEvent`, then inspect `EventName` to route the event and `Data` to process the payload. Use `LastEventId` and `Retry` when the stream provides reconnection or event-position information.

## Object creation, unlocking and error handling

**Object Creation**

```tcl
# 'this' is not a keyword in Tcl. It can freely be used as a variable name.
set this [new CkServerSentEvent]
```

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in Tcl.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `string # ckStr is a CkString CkServerSentEvent_get_DebugLogFilePath $this $ckStr set strVal [CkServerSentEvent_get_debugLogFilePath $this] CkServerSentEvent_put_DebugLogFilePath $this $strVal` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `string # ckStr is a CkString CkServerSentEvent_get_LastErrorHtml $this $ckStr set strVal [CkServerSentEvent_get_lastErrorHtml $this]` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `string # ckStr is a CkString CkServerSentEvent_get_LastErrorText $this $ckStr set strVal [CkServerSentEvent_get_lastErrorText $this]` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `string # ckStr is a CkString CkServerSentEvent_get_LastErrorXml $this $ckStr set strVal [CkServerSentEvent_get_lastErrorXml $this]` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `boolean 1/0 set boolVal [CkServerSentEvent_get_LastMethodSuccess $this] CkServerSentEvent_put_LastMethodSuccess $this $boolVal` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `Utf8` | `boolean 1/0 set boolVal [CkServerSentEvent_get_Utf8 $this] CkServerSentEvent_put_Utf8 $this $boolVal` | read/write | When set to `1`, all `string` arguments and return values are interpreted as UTF-8 strings. |
| `VerboseLogging` | `boolean 1/0 set boolVal [CkServerSentEvent_get_VerboseLogging $this] CkServerSentEvent_put_VerboseLogging $this $boolVal` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `string # ckStr is a CkString CkServerSentEvent_get_Version $this $ckStr set strVal [CkServerSentEvent_get_version $this]` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `Data` | property, read-only | `string # ckStr is a CkString CkServerSentEvent_get_Data $this $ckStr set strVal [CkServerSentEvent_get_data $this]` |
| `EventName` | property, read-only | `string # ckStr is a CkString CkServerSentEvent_get_EventName $this $ckStr set strVal [CkServerSentEvent_get_eventName $this]` |
| `LastEventId` | property, read-only | `string # ckStr is a CkString CkServerSentEvent_get_LastEventId $this $ckStr set strVal [CkServerSentEvent_get_lastEventId $this]` |
| `Retry` | property, read-only | `integer set intVal [CkServerSentEvent_get_Retry $this]` |
| `LoadEvent` | method | `# eventText is a string set status [CkServerSentEvent_LoadEvent $this $eventText]` |

## Properties

### ServerSentEvent.Data

`Chilkat 11.7.0 · tcl · ServerSentEvent · Data · property · read-only · since 9.5.0.58`

```tcl
string
# ckStr is a CkString

CkServerSentEvent_get_Data $this $ckStr

set strVal [CkServerSentEvent_get_data $this]
```

The data for the server-side event. (If the `data` field was empty, then this will be empty.)

### ServerSentEvent.EventName

`Chilkat 11.7.0 · tcl · ServerSentEvent · EventName · property · read-only · since 9.5.0.58`

```tcl
string
# ckStr is a CkString

CkServerSentEvent_get_EventName $this $ckStr

set strVal [CkServerSentEvent_get_eventName $this]
```

The name of the server-side event. (If the `event` field was not present, then this will be empty.)

### ServerSentEvent.LastEventId

`Chilkat 11.7.0 · tcl · ServerSentEvent · LastEventId · property · read-only · since 9.5.0.58`

```tcl
string
# ckStr is a CkString

CkServerSentEvent_get_LastEventId $this $ckStr

set strVal [CkServerSentEvent_get_lastEventId $this]
```

The content of the `id` field, if present.

### ServerSentEvent.Retry

`Chilkat 11.7.0 · tcl · ServerSentEvent · Retry · property · read-only · since 9.5.0.58`

```tcl
integer
set intVal [CkServerSentEvent_get_Retry $this]
```

The integer value of the `retry` field, if it exists; otherwise, 0.

## Methods

### ServerSentEvent.LoadEvent

`Chilkat 11.7.0 · tcl · ServerSentEvent · LoadEvent · method · since 9.5.0.58`

```tcl
# eventText is a string

set status [CkServerSentEvent_LoadEvent $this $eventText]
```

Loads the multi-line event text into this object. For example, the `eventText` for a Firebase event might look like this:

```
event: put
data: {"path": "/c", "data": {"foo": true, "bar": false}}
```

Returns 1 for success, 0 for failure.

