example-websocket icon indicating copy to clipboard operation
example-websocket copied to clipboard

example server + client fails

Open bjornstromberg opened this issue 2 years ago • 3 comments

see https://github.com/oatpp/oatpp-websocket/issues/38#issuecomment-1173165297 it seems to be the same issue.

I |2022-07-03 22:13:13 1656879193764964| websocket-client:Application Started
 I |2022-07-03 22:13:14 1656879194377704| websocket-client:Connected
 D |2022-07-03 22:13:14 1656879194378063| websocket-client:sending message...
 D |2022-07-03 22:13:14 1656879194379271| [oatpp::web::protocol::websocket::WebSocket::listen()]:Unhandled error occurred. Message='[oatpp::web::protocol::websocket::WebSocket::readFrameHeader()]: Error reading frame header'
 D |2022-07-03 22:13:14 1656879194379349| websocket-client:SOCKET CLOSED!!!

bjornstromberg avatar Jul 03 '22 20:07 bjornstromberg

well it seems its more of a bad description of what should happen.

client connects to third party api online.

expected a client / server local ping pong

bjornstromberg avatar Jul 05 '22 08:07 bjornstromberg

Hello @bjornstromberg ,

It looks that API key for demo server is expired. I've updated the API key in the example and it works:

  auto connection = connector->connect("v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self");

lganzzzo avatar Aug 30 '22 22:08 lganzzzo

well it seems its more of a bad description of what should happen.

client connects to third party api online.

expected a client / server local ping pong

The 'client' example can be modified to connect to localhost with the 'server' example with



int local = 1;
  std::string url = "localhost";
  uint16_t port = 8000;
  std::string conn_str = "ws";
  if (!local)
  {
    url = "demo.piesocket.com";
    port = 80;
    conn_str = "v3/channel_1?api_key=oCdCMcMPQpbvNjUIzqtvF1d2X2okWpDQj4AwARJuAgtjhzKxVEjQU6IdCjwm&notify_self";
  }

  auto connectionProvider = oatpp::network::tcp::client::ConnectionProvider::createShared({url, port});

  auto connector = oatpp::websocket::Connector::createShared(connectionProvider);

  auto connection = connector->connect(conn_str);

and the examples can be easily build by modifying the main CMake file in /src to have at the end


include_directories(.)

add_library(oatpp-websocket
        oatpp-websocket/src/oatpp-websocket/AsyncConnectionHandler.cpp
        oatpp-websocket/src/oatpp-websocket/AsyncConnectionHandler.hpp
        oatpp-websocket/src/oatpp-websocket/AsyncWebSocket.cpp
        oatpp-websocket/src/oatpp-websocket/AsyncWebSocket.hpp
        oatpp-websocket/src/oatpp-websocket/Config.hpp
        oatpp-websocket/src/oatpp-websocket/ConnectionHandler.cpp
        oatpp-websocket/src/oatpp-websocket/ConnectionHandler.hpp
        oatpp-websocket/src/oatpp-websocket/Connector.cpp
        oatpp-websocket/src/oatpp-websocket/Connector.hpp
        oatpp-websocket/src/oatpp-websocket/Frame.cpp
        oatpp-websocket/src/oatpp-websocket/Frame.hpp
        oatpp-websocket/src/oatpp-websocket/Handshaker.cpp
        oatpp-websocket/src/oatpp-websocket/Handshaker.hpp
        oatpp-websocket/src/oatpp-websocket/SHA1.cpp
        oatpp-websocket/src/oatpp-websocket/SHA1.hpp
        oatpp-websocket/src/oatpp-websocket/Utils.cpp
        oatpp-websocket/src/oatpp-websocket/Utils.hpp
        oatpp-websocket/src/oatpp-websocket/WebSocket.cpp
        oatpp-websocket/src/oatpp-websocket/WebSocket.hpp
)

include_directories(oatpp-websocket/src)

add_executable(client
        example-websocket/client/src/App.cpp
        example-websocket/client/src/WSListener.cpp
        example-websocket/client/src/WSListener.hpp
)

add_executable(server
        example-websocket/server/src/App.cpp
        example-websocket/server/src/AppComponent.hpp
        example-websocket/server/src/websocket/WSListener.cpp
        example-websocket/server/src/websocket/WSListener.hpp
)

target_link_libraries(client oatpp-websocket oatpp)
target_link_libraries(server oatpp-websocket oatpp)


pedro-vicente avatar May 22 '23 07:05 pedro-vicente