GenHTTP icon indicating copy to clipboard operation
GenHTTP copied to clipboard

Add support for Websockets (RFC 6455)

Open Kaliumhexacyanoferrat opened this issue 5 years ago • 10 comments

As a developer of a reactive, rich client-application, I would like to use websocket connections to the webserver, so that I can easily push content from the server to the clients.

Example

Very vague - clarity comes with implementation.

class IWebsocketHandler 
{
    void Initialize(Connection connection);
    void HandleFrame(Frame frame);
}

var socket = Websocket.Create<MyHandler>();

Acceptance criteria

  • The Websocket handler is a regular IHandler that can be added where required
  • There is a separate GenHTTP.Modules.Websocket module, with a minimal hook into the server core to gain control over the socket

Kaliumhexacyanoferrat avatar Sep 02 '20 21:09 Kaliumhexacyanoferrat

This would be quite helpful to have

ToshiroZ avatar May 03 '22 21:05 ToshiroZ

Websockets, along with form-based authentication, are the next topics on the agenda.

Due to my parental leave in summer, there will be few changes from my side in the next months. Pull requests or preparatory changes are of course always welcome.

Kaliumhexacyanoferrat avatar May 04 '22 07:05 Kaliumhexacyanoferrat

Would it also be possible to render a page without any theming? Basically increment some data then view page

On Wed, May 4, 2022, 3:30 AM Andreas Nägeli @.***> wrote:

Websockets, along with form-based authentication, are the next topics on the agenda.

Due to my parental leave in summer, there will be few changes from my side in the next months. Pull requests or preparatory changes are of course always welcome.

— Reply to this email directly, view it on GitHub https://github.com/Kaliumhexacyanoferrat/GenHTTP/issues/82#issuecomment-1117007708, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALTBPP7KTHBSJ755RAWXKVTVIIRSLANCNFSM4QTZJ52Q . You are receiving this because you commented.Message ID: @.***>

ToshiroZ avatar May 05 '22 03:05 ToshiroZ

If you would like to use the Website module, you will need a theme - an empty theme should not be much effort. If you do not need the features provided by the Website, you can just render a Page in the default server theme:

var page = Page.From("My Content") // or ModScriban.Page() or ModRazor.Page() or Placeholders.Page()
               .Title("My Title")
               .Description("My description");

var layout = Layout.Create()
                   .Add("page", page); // http://localhost:8080/page

Host.Create()
    .Handler(layout)
    .Defaults()
    .Development()
    .Console()
    .Run();

Razor and Scriban allow you to render a model into a template (e.g. read from the file system).

Kaliumhexacyanoferrat avatar May 05 '22 10:05 Kaliumhexacyanoferrat

Or, if you are fine with plain text, even easier:

var handler = Inline.Create()
                    .Get("/page", () => "Hello World!");

Host.Create()
    .Handler(handler)
    .Run();

Kaliumhexacyanoferrat avatar May 05 '22 11:05 Kaliumhexacyanoferrat

How about the websocket module, is it ready for use?

yuexueyang avatar Aug 09 '23 10:08 yuexueyang