【问题标题】:websocketpp | Can't set on_close/ open handlerwebsocketpp |无法设置 on_close/打开处理程序
【发布时间】:2019-10-06 12:22:34
【问题描述】:

当我尝试设置 set_close_handler 时,我遇到了这个异常:

rm -rf build/*.o main command_prompt
rm -rf *.o main command_prompt
g++ -o build//main.o -std=c++11 -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY -D__BASEFILE__=\"build/main\" -c -Ilibs/lmic/src -Ilibs/  main.cpp
main.cpp: In function ‘void on_close(websocketpp::connection_hdl)’:
main.cpp:75:3: error: ‘m_connections’ was not declared in this scope
   m_connections.erase(hdl);
   ^~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:226:70: error: expected primary-expression before ‘)’ token
       echo_server.set_close_handler(bind(&on_close,&echo_server,::_1,));
                                                                      ^
Makefile:29: recipe for target 'build/main.o' failed
make: *** [build/main.o] Error 1
rebuild.sh: line 3: ./main: No such file or directory

我已经尝试在 on_close 事件中使用参数和客户端指针,但这并没有改变任何事情。 我已经成功设置了 on 消息处理程序,但是当我尝试设置 on open 处理程序时,它会抛出相同的异常。

void on_close(websocketpp::connection_hdl hdl)

}

echo_server.set_close_handler(bind(&on_close,&echo_server,::_1,));

【问题讨论】:

    标签: c++ sockets websocket


    【解决方案1】:

    包含这一行应该可以解决您的问题:

    using websocketpp::lib::placeholders::_1;
    

    【讨论】:

      【解决方案2】:
      echo_server.set_close_handler(bind(&on_close,&echo_server,::_1, ));
                                                                     ^
                                                  missing an argument here                    
      

      【讨论】:

      • 哎呀,抱歉在发布前忘记删除它,这不是异常的原因。
      猜你喜欢
      • 1970-01-01
      • 2021-11-01
      • 2011-04-11
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多