123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include "web_connect.h"
- #include<thread>
- #include<chrono>
- #include <tool_time.h>
- #include"log.h"
- #include"wsClientMgr.h"
- #include"wsTimerThread.h"
- #define BEATHEART_COUNT_NUM 1000
- web_connect::web_connect()
- {
- }
- void web_connect::init(const std::vector<std::string>&uri_list,int32_t st, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
- {
-
- swsClientMgr.Build( uri_list, MsgFuncList );
-
- YA::_THREAD_CONFIG_ Config;
- Config.SendInterval = st;
- swsTimerThrd.Init( Config );
- }
- void web_connect::start_beatheart_monitor()
- {
- auto th = std::thread(&web_connect::_beatheart_thread);
- th.detach();
- }
- void web_connect::close()
- {
- swsTimerThrd.Stop();
- swsClientMgr.close();
- }
- bool web_connect::connect()
- {
-
- if ( swsClientMgr.connect() != 0 )
- {
- log_error("web socket 连接失败....");
- std_error("websocket 连接失败....");
- return false;
- }
-
- swsClientMgr.login();
- swsTimerThrd.Start();
- return true;
- }
- void web_connect::_beatheart_thread()
- {
- while (true)
- {
- std::this_thread::sleep_for(std::chrono::seconds(3));
- swsClientMgr.CheckClientConnect(tool_time::now_to_seconds());
-
- }
- }
|