13 changed files with 71 additions and 10 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +1,58 @@ |
|||
#include <cstdio> |
|||
#include <iostream> |
|||
using namespace std; |
|||
#include <websocketpp/config/asio_no_tls.hpp> |
|||
#include <websocketpp/server.hpp> |
|||
// 0.定义server_t类型
|
|||
typedef websocketpp::server<websocketpp::config::asio> server_t; |
|||
|
|||
void OnOpen(websocketpp::connection_hdl hdl) |
|||
{ |
|||
std::cout << "Websocket长连接建立成功" << std::endl; |
|||
} |
|||
|
|||
void OnClose(websocketpp::connection_hdl hdl) |
|||
{ |
|||
std::cout << "Websocket长连接断开" << std::endl; |
|||
} |
|||
|
|||
void OnMessage(server_t* svr, websocketpp::connection_hdl hdl, server_t::message_ptr msg) |
|||
{ |
|||
std::string body = msg->get_payload(); |
|||
std::cout << "Get Msg: " << body << std::endl; |
|||
|
|||
auto conn = svr->get_con_from_hdl(hdl); |
|||
|
|||
conn->send(body + "-Response", websocketpp::frame::opcode::value::text); |
|||
} |
|||
|
|||
int main() |
|||
{ |
|||
cout << "你好,这是我的第一个在Linux上部署调试的CPP文件"<<endl; |
|||
printf("%s 向你问好!\n", "ConsoleApplication3"); |
|||
return 0; |
|||
// 1.实例化服务器对象
|
|||
server_t svr; |
|||
|
|||
// 2.初始化日志输出 --> 关闭日志输出
|
|||
svr.set_access_channels(websocketpp::log::alevel::none); |
|||
|
|||
// 3.初始化ASIO框架
|
|||
svr.init_asio(); |
|||
|
|||
// 4.设置消息处理/连接握手成功/连接关闭回调函数
|
|||
svr.set_open_handler(OnOpen); |
|||
svr.set_close_handler(OnClose); |
|||
auto msg_handler = std::bind(OnMessage, &svr, std::placeholders::_1, |
|||
std::placeholders::_2); |
|||
svr.set_message_handler(msg_handler); |
|||
|
|||
// 5.启用地址重用
|
|||
svr.set_reuse_addr(true); |
|||
|
|||
// 6.设置监听端口
|
|||
svr.listen(8081); |
|||
|
|||
// 7.开始监听
|
|||
svr.start_accept(); |
|||
|
|||
// 8.启动服务器
|
|||
svr.run(); |
|||
|
|||
} |
@ -1 +1 @@ |
|||
E:\DataFile\ProjectX\TalkingWeb\ConsoleApplication3\main.cpp|638753481411401034|/root/ProjectCpp/root/ProjectCpp/ConsoleApplication3/||g++ -c -x c++ /root/ProjectCpp/root/ProjectCpp/ConsoleApplication3/main.cpp -I /usr/include -g2 -gdwarf-2 -o "/root/ProjectCpp/root/ProjectCpp/ConsoleApplication3/obj/x64/Debug/main.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O0 -fno-strict-aliasing -fno-omit-frame-pointer -fthreadsafe-statics -fexceptions -frtti -std=c++11 |
|||
E:\DataFile\ProjectX\TalkingWeb\ConsoleApplication3\main.cpp|638753491610634226|/root/ProjectCpp/root/ProjectCpp/ConsoleApplication3/||g++ -c -x c++ /root/ProjectCpp/root/ProjectCpp/ConsoleApplication3/main.cpp -I /usr/include -g2 -gdwarf-2 -o "/root/ProjectCpp/root/ProjectCpp/ConsoleApplication3/obj/x64/Debug/main.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O0 -fno-strict-aliasing -fno-omit-frame-pointer -fthreadsafe-statics -fexceptions -frtti -std=c++11 |
|||
|
@ -1 +1 @@ |
|||
E:\DataFile\ProjectX\TalkingWeb\ConsoleApplication3\main.cpp|638753481411401034|/root/ProjectCpp//root/ProjectCpp/ConsoleApplication3/| |
|||
E:\DataFile\ProjectX\TalkingWeb\ConsoleApplication3\main.cpp|638753491610634226|/root/ProjectCpp//root/ProjectCpp/ConsoleApplication3/| |
|||
|
@ -0,0 +1,12 @@ |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\1622921215.compileuptodatefile.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\1622921215.linkuptodatefile.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\1622921215.copysourcesuptodatefile.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\1622921215.local_remote_pathmapping.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\1622921215.remoteprojectdirfile.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\lastremotetarget.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\bin\x64\debug\consoleapplication3.out |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\consoleapplication3.vcxproj.filelistabsolute.txt |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\consolea.cca6b3fc.tlog\cl.items.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\consolea.cca6b3fc.tlog\compile.read.1.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\consolea.cca6b3fc.tlog\compile.write.1.tlog |
|||
e:\datafile\projectx\talkingweb\consoleapplication3\obj\x64\debug\consolea.cca6b3fc.tlog\link.write.1.tlog |
Loading…
Reference in new issue