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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidhandle(HttpExchange exchange) Do not override this method, it will causeSimpleHttpHandler.handle(SimpleHttpExchange)to not work.final voidhandle(SimpleHttpExchange exchange) Handles an exchange.final voidPushes an event to the stream.final voidPushes 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:SimpleHttpHandlerDo not override this method, it will causeSimpleHttpHandler.handle(SimpleHttpExchange)to not work. UseSimpleHttpHandler.handle(SimpleHttpExchange)instead.- Specified by:
handlein interfaceHttpHandler- Specified by:
handlein 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:SimpleHttpHandlerHandles 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:
handlein 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
-