Add websocket support by gre-42 · Pull Request #236 · etr/libhttpserver · GitHub
Skip to content

Add websocket support#236

Open
gre-42 wants to merge 1 commit into
etr:masterfrom
gre-42:master
Open

Add websocket support#236
gre-42 wants to merge 1 commit into
etr:masterfrom
gre-42:master

Conversation

@gre-42

@gre-42 gre-42 commented Jun 21, 2021

Copy link
Copy Markdown

Issue or RFC Endorsed by Maintainers

Enable WebSockets #20.

Description of the Change

Added websocket support.

Alternate Designs

Extending the existing http_resource class was considered, but rejected in favor of a new class and multiple inheritance.

Possible Drawbacks

libmicrohttpserver does not yet compile the websocket-support by default. It must be done by building libmicrohttpd/src/microhttpd_ws.

Verification Process

Created and tested an example application hello_world_websocket.cpp under Ubuntu 20.04.

Release Notes

Added support for websockets.

@nawaz1991

Copy link
Copy Markdown

@etr

etr commented Sep 10, 2021

Copy link
Copy Markdown
Owner

Sorry for the lack on feedback and thanks for the support and for the code contribution.

I think the main reason I cannot go with this change as is currently wired is that it uses a custom version/configuration of libmicrohttpd without making it optional. I think that needs to be solved before we can merge this change - many consumers of the library use libmicrohttpd as installed by their OSes and this would practically break their builds entirely.

@nawaz1991

Copy link
Copy Markdown

Sorry for the lack on feedback and thanks for the support and for the code contribution.

I think the main reason I cannot go with this change as is currently wired is that it uses a custom version/configuration of libmicrohttpd without making it optional. I think that needs to be solved before we can merge this change - many consumers of the library use libmicrohttpd as installed by their OSes and this would practically break their builds entirely.

Thanks for the quick reply.

@jvo203

jvo203 commented Jan 22, 2024

Copy link
Copy Markdown

Whilst I appreciate concerns for the existing user base, change is inevitable. It is called progress. Existing projects relying on libmicrohttpd would need to update / re-compile their code. Just like all the other open-source projects do when there are API breaks in their codebases and / or dependencies.

I've been a faithful libmicrohttpd user for nearly 10 years. It is just great, the API is ergonomic, the MHD_create_response_from_pipe() function is much appreciated too. But the lack of WebSocket support has always forced me into "clunky" hybrid solutions: for example right now using libmicrohttpd on port 8080 to handle HTTP and a separate thread running the C mongoose library on port 8081 to handle WebSockets. Dealing with two different C APIs as well as frequent changes in the C mongoose API (change is inevitable but hopefully not too frequently!). Not ideal at all.

@jvo203

jvo203 commented Jan 22, 2024

Copy link
Copy Markdown

Verification Process

Created and tested an example application hello_world_websocket.cpp under Ubuntu 20.04.

Hi are there any plans to provide a C-only WebSocket example? My project uses FORTRAN and pure C with no C++ whatsoever.

@LeSpocky

LeSpocky commented Oct 17, 2025

Copy link
Copy Markdown
Contributor

@jvo203

jvo203 commented Oct 17, 2025

Copy link
Copy Markdown

@LeSpocky that's really a pity.

@LeSpocky

Copy link
Copy Markdown
Contributor

The upgrade handling is still in place. I guess you would just need to handle the socket you get with some other code. Will look into that later.

@jvo203

jvo203 commented Oct 17, 2025

Copy link
Copy Markdown

That's great to hear. This is what I am already doing, handling the WebSocket messages (a TCP connection) in a custom C code after the initial upgrade.

@jvo203

jvo203 commented Oct 17, 2025

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants