java.lang.Object
dev.katsute.simplehttpserver.handler.SSEHandler
- All Implemented Interfaces:
HttpHandler
,SimpleHttpHandler
A Server sent events (SSE) handler sends events from the server to a client using an
text/event-stream
. Events are sent using push(String)
or push(String, int, String)
.- Since:
- 5.0.0
- Version:
- 5.0.0
- Author:
- Katsute
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
handle
(HttpExchange exchange) Do not override this method, it will causeSimpleHttpHandler.handle(SimpleHttpExchange)
to not work.final void
handle
(SimpleHttpExchange exchange) Handles an exchange.final void
Pushes an event to the stream.final void
Pushes an event to the streamtoString()
-
Constructor Details
-
SSEHandler
public SSEHandler()Creates a SSE handler.- Since:
- 5.0.0
-
-
Method Details
-
handle
Description copied from interface:SimpleHttpHandler
Do not override this method, it will causeSimpleHttpHandler.handle(SimpleHttpExchange)
to not work. UseSimpleHttpHandler.handle(SimpleHttpExchange)
instead.- Specified by:
handle
in interfaceHttpHandler
- Specified by:
handle
in interfaceSimpleHttpHandler
- Parameters:
exchange
- the exchange containing the request from the client and used to send the response- Throws:
IOException
- IO exception- See Also:
-
handle
Description copied from interface:SimpleHttpHandler
Handles an exchange.
Http handlers will not throw an exception in the main thread, you must use a try-catch to expose them. All requests must be closed withHttpExchange.close()
, otherwise the handler will rerun the request multiple times.- Specified by:
handle
in interfaceSimpleHttpHandler
- Parameters:
exchange
- http exchange- Throws:
IOException
- IO exception- See Also:
-
push
Pushes an event to the stream.- Parameters:
data
- data to send- Since:
- 5.0.0
- See Also:
-
push
Pushes an event to the stream- Parameters:
data
- data to sendretry
- how long to retry forevent
- event type- Since:
- 5.0.0
- See Also:
-
toString
-