Kaliumhexacyanoferrat / GenHTTP

Lightweight web server written in pure C# with few dependencies to 3rd-party libraries.
https://genhttp.org
MIT License
188 stars 30 forks source link

Add support for Websockets (RFC 6455) #82

Closed Kaliumhexacyanoferrat closed 2 weeks ago

Kaliumhexacyanoferrat commented 4 years ago

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

ToshiroZ commented 2 years ago

This would be quite helpful to have

Kaliumhexacyanoferrat commented 2 years ago

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.

ToshiroZ commented 2 years ago

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: @.***>

Kaliumhexacyanoferrat commented 2 years ago

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 commented 2 years ago

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

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

Host.Create()
    .Handler(handler)
    .Run();
yuexueyang commented 1 year ago

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

Fiahblade commented 2 months ago

Are there still plans to include this feature?

Kaliumhexacyanoferrat commented 1 month ago

Yes, web sockets are one of the more important features but as the protocol is rather complex that will take some effort to be implemented.

Kaliumhexacyanoferrat commented 2 weeks ago

Notes: Probably do not implement this ourselves but reuse an existing library and just pass the server socket together with some glue code for upgrading the connection. Need to check whether this is possible in one of the suspects.

Kaliumhexacyanoferrat commented 2 weeks ago

Will be available with GenHTTP version 9 in November.