Class SseConnection

java.lang.Object
io.karatelabs.http.SseConnection

public class SseConnection extends Object
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 Details

    • send

      public void send(String event, String data)
      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

      public void send(String data)
      Send an SSE event with data only (no event name).
    • sendComment

      public void sendComment(String comment)
      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

      public void onDisconnect(Runnable callback)
      Register a callback for when the client disconnects.