Package io.karatelabs.http
Class SseConnection
java.lang.Object
io.karatelabs.http.SseConnection
Server-Sent Events connection wrapping a Netty channel.
Sends the initial HTTP response headers with chunked transfer encoding,
then allows sending individual SSE events as data frames.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the SSE connection by sending the last chunk and closing the channel.booleanisOpen()voidonDisconnect(Runnable callback) Register a callback for when the client disconnects.voidSend an SSE event with data only (no event name).voidSend an SSE event with the given event name and data.voidsendComment(String comment) Send an SSE comment (line starting with colon).
-
Method Details
-
send
Send an SSE event with the given event name and data.- Parameters:
event- the event name (appears as "event: name" in the stream)data- the event data (appears as "data: ..." lines)
-
send
Send an SSE event with data only (no event name). -
sendComment
Send an SSE comment (line starting with colon). Useful as a keep-alive. -
close
public void close()Close the SSE connection by sending the last chunk and closing the channel. -
isOpen
public boolean isOpen() -
onDisconnect
Register a callback for when the client disconnects.
-