svenkubiak / mangooio

An Intuitive, Lightweight, High Performance Full Stack Java Web Framework.
Apache License 2.0
56 stars 12 forks source link

Web Sockets & Server Sent Events #596

Open name256a opened 1 month ago

name256a commented 1 month ago

Good day,

Do you have any example that illustrates how the above can be developed using the framework?

Regards

svenkubiak commented 1 week ago

Sorry for the late reply. While there is no support for Web Sockets, usage of ServerSentEvent on the server side is quite easy.

Setup your SSE URL in initializeRoutes() in the Bootstrap class, e.g.

...
Bind.serverSentEvent().to("/mysse");
...

Then send data to your SSE endpoint using the ServerSentEventManager at any point in your application.

...
private final ServerSentEventManager sse;
...
sse.send("/sse", "myData");
...

Everything else is handled on the client side, e.g.

https://www.w3schools.com/html/html5_serversentevents.asp