Skip to content

Echo WebSocket server example broken #1402

@Neverlord

Description

@Neverlord

As reported in chat, examples/web_socket/echo is broken in 0.19. Connection aborts right after clients connect. With this patch:

diff --git a/examples/web_socket/echo.cpp b/examples/web_socket/echo.cpp
index 86163f5e0..b1b995b94 100644
--- a/examples/web_socket/echo.cpp
+++ b/examples/web_socket/echo.cpp
@@ -93,17 +93,25 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
                 // ... that simply pushes data back to the sender.
                 auto [pull, push] = ev.data();
                 pull.observe_on(self)
-                  .do_on_next([](const ws::frame& x) {
-                    if (x.is_binary()) {
-                      std::cout
-                        << "*** received a binary WebSocket frame of size "
-                        << x.size() << '\n';
-                    } else {
-                      std::cout
-                        << "*** received a text WebSocket frame of size "
-                        << x.size() << '\n';
-                    }
+                  .do_on_error([](const caf::error& what) { //
+                    std::cout << "*** connection closed: " << to_string(what)
+                              << "\n";
                   })
+                  .do_on_complete([] { //
+                    std::cout << "*** connection closed\n";
+                  })
+                  .do_on_next(
+                    [](const ws::frame& x) {
+                      if (x.is_binary()) {
+                        std::cout
+                          << "*** received a binary WebSocket frame of size "
+                          << x.size() << '\n';
+                      } else {
+                        std::cout
+                          << "*** received a text WebSocket frame of size "
+                          << x.size() << '\n';
+                      }
+                    })
                   .subscribe(push);
               });
           });

I get: *** connection closed: caf::sec::disposed("destroyed producer_resource without opening it").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions