-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of raw transport for websocket #2914
Comments
Yes it is possible to implement a custom transport. No, I cannot share an example. It is expected that users are able to read the concept requirements and be able to create a working implementation from those requirements. For reference, here are the requirements that you must implement: https://www.boost.org/doc/libs/1_85_0/doc/html/boost_asio/reference/AsyncReadStream.html You will also need to provide an overload of the functions https://www.boost.org/doc/libs/1_85_0/libs/beast/doc/html/beast/using_websocket/teardown.html If you get stuck and you have specific questions, consider asking in the Official C++ Language Slack Workspace (https://cpp.al/slack) |
Thank you for the answer. I already tried to implement AsyncReadStream/AsyncWriteStream interfaces. But seems it is not enough for custom transport class. Below is an example of a maximally simplified class where the necessary methods are declared.
But I got compilation error. Probably the class must satisfy some other requirements. Are these additional requirements written somewhere?
|
You need to provide an overload of the function beast_close_socket too: void
beast_close_socket(NextLayerImpl_&)
{
} |
@ashtum Thank you, this helped to compile the application. Could you tell me concrete types for MB and Handler? I need to save this parameters as class fields. I need this to fill them out later, when I got data from inner transport infrastructure.
I tried to use boost::beast::detail::BufferSequenceboost::asio::mutable_buffer instead of MB, but got a compilation error
|
The Handler is not a regular function object; it is an Asio Completion Token. You can only use it through async_initiate. You can use any_completion_handler for type-erasing the handler, but it still needs to go through async_initiate first. Here is an example: https://github.com/boostorg/asio/tree/develop/example/cpp11/type_erasure. Regarding the buffer sequence types, there is no concrete type for them. They have different types in different operations, and you need to create a type-erased wrapper for the Mutable buffer sequence and Constant buffer sequence concepts. |
@ashtum I will try this, thank you for the reply |
I have a single thread application which can process TCP connections (some implementation of Reactor pattern).
I want to add possibility to process websocket connections.
Let's assume that I have established TCP connection in which I can send data and from which I can receive data through onRecv-callback.
I want to implement some custom transport-adapter to use it TCP-connection with boost::beast websocket.
I managed to do this using the websocketpp (https://github.com/zaphoyd/websocketpp) library.
But later I came across an article on the official boost site (https://www.boost.org/doc/libs/1_66_0/libs/beast/doc/html/beast/design_choices/comparison_to_zaphoyd_studios_we.html) in which says that boost::beast can do the same thing but only better.
But I have not found a single example that would confirm this. It seems I should implement
AsyncReadStream
,AsyncWriteStream
, but also no examples of how to do this.Is it possible to impement custom transport with for beast websocket? And if so, can you share some examples?
The text was updated successfully, but these errors were encountered: