|
@ -6,7 +6,9 @@ using namespace core; |
|
|
using namespace ix; |
|
|
using namespace ix; |
|
|
|
|
|
|
|
|
void IflytopWSService::initialize() { |
|
|
void IflytopWSService::initialize() { |
|
|
m_server.reset(new WebSocketServer(19001)); |
|
|
|
|
|
|
|
|
logger->info("IflytopWSService initialize {}", 19001); |
|
|
|
|
|
|
|
|
|
|
|
m_server.reset(new WebSocketServer(19001,"0.0.0.0")); |
|
|
m_server->setOnConnectionCallback([this](weak_ptr<WebSocket> webSocket, shared_ptr<ConnectionState> connectionState) { |
|
|
m_server->setOnConnectionCallback([this](weak_ptr<WebSocket> webSocket, shared_ptr<ConnectionState> connectionState) { |
|
|
logger->info("Remote ip: {}", connectionState->getRemoteIp()); |
|
|
logger->info("Remote ip: {}", connectionState->getRemoteIp()); |
|
|
auto ws = webSocket.lock(); |
|
|
auto ws = webSocket.lock(); |
|
@ -27,12 +29,19 @@ void IflytopWSService::initialize() { |
|
|
} |
|
|
} |
|
|
m_server->disablePerMessageDeflate(); |
|
|
m_server->disablePerMessageDeflate(); |
|
|
m_server->start(); |
|
|
m_server->start(); |
|
|
m_server->wait(); |
|
|
|
|
|
|
|
|
// m_server->wait();
|
|
|
|
|
|
logger->info("IflytopWSService initialize done"); |
|
|
|
|
|
m_initialized = false; |
|
|
} |
|
|
} |
|
|
void IflytopWSService::sendMessage(const string& message) { |
|
|
void IflytopWSService::sendMessage(const string& message) { |
|
|
|
|
|
if (!m_initialized) { |
|
|
|
|
|
logger->error("IflytopWSService not initialized"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
/**
|
|
|
/**
|
|
|
* @brief 广播消息给所有连接的客户端 |
|
|
* @brief 广播消息给所有连接的客户端 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
logger->debug("uplink msg: {}", message); |
|
|
auto clients = m_server->getClients(); |
|
|
auto clients = m_server->getClients(); |
|
|
for (auto& each : clients) { |
|
|
for (auto& each : clients) { |
|
|
if (each) { |
|
|
if (each) { |
|
@ -52,10 +61,7 @@ void IflytopWSService::onMessageCallback(weak_ptr<WebSocket> webSocket, shared_p |
|
|
} |
|
|
} |
|
|
onConnect(webSocket, msg); |
|
|
onConnect(webSocket, msg); |
|
|
} else if (msg->type == ix::WebSocketMessageType::Message) { |
|
|
} else if (msg->type == ix::WebSocketMessageType::Message) { |
|
|
// auto ws = webSocket.lock();
|
|
|
|
|
|
// if (ws) {
|
|
|
|
|
|
// ws->send(msg->str, msg->binary);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
logger->debug("downlink msg: {}", msg->str); |
|
|
onMessage(webSocket, msg); |
|
|
onMessage(webSocket, msg); |
|
|
} else if (msg->type == ix::WebSocketMessageType::Close) { |
|
|
} else if (msg->type == ix::WebSocketMessageType::Close) { |
|
|
logger->info("{} Closed connection", msg->closeInfo.remote); |
|
|
logger->info("{} Closed connection", msg->closeInfo.remote); |
|
|