beast icon indicating copy to clipboard operation
beast copied to clipboard

Feature Request: Support for WebSocket over Unix Domain Sockets

Open zhengfeihe opened this issue 1 year ago • 6 comments

Hi Maintainers,

I have found, support for using custom external sockets is not available in beast, as noted in this issue. Specifically, I encountered this limitation when trying to use WebSocket over Unix sockets. This seems to be a missing feature in many C++ WebSocket libraries. There were also issues related to using WebSockets over Unix domain sockets in websocketpp, but it appears to be unmaintained.

Building WebSocket communication over Unix domain sockets is supported in some packages for other languages. For example, in Python's websocket-client package, you can configure a Unix domain socket when creating client connections: websocket-client.

Do you think this is a feature that could be added to Beast? If so, would it be acceptable for me to work on this? It may take some time for me to implement.

Best, Zhengfei

zhengfeihe avatar Aug 10 '24 13:08 zhengfeihe

You can easily use a different socket type for the underlying stream of websocket::stream:

using ws_stream_t = beast::websocket::stream<asio::local::stream_protocol::socket>;

The websocket::stream::next_layer function gives you access to the underlying stream, allowing you to perform the connect operation. Alternatively, you can move an already connected socket into the websocket stream constructor.

ashtum avatar Aug 10 '24 16:08 ashtum

We should provide a working example program for this since it keeps coming up.

vinniefalco avatar Aug 10 '24 16:08 vinniefalco

Thanks for your reply and explanation! I will close the issue.

zhengfeihe avatar Aug 11 '24 15:08 zhengfeihe

I would also add an example with Windows Named Pipe. I know, Windows supports UNIX domain sockets since Windows 10, but named pipes has better Windows Security support (you can run named pipe with own security descriptor).

savely-krasovsky avatar Aug 17 '24 19:08 savely-krasovsky

Does asio have a windows named pipe implementation that meets the stream requirements?

vinniefalco avatar Aug 17 '24 23:08 vinniefalco

@vinniefalco yes: https://www.boost.org/doc/libs/1_86_0/doc/html/boost_asio/overview/windows/stream_handle.html I tried it with http client, works perfectly.

savely-krasovsky avatar Aug 18 '24 02:08 savely-krasovsky