OnConnectは、UDP接続が正常に確立されると呼び出されます。
DiarkisUdpBase.h
class DIARKIS_API DiarkisUdpBase
{
protected:
void OnConnect(bool isReconnect);
void OnConnect(bool isReconnect);
void OnDisconnect(bool isReconnect);
void OnResponse(const DiarkisResponseEventArgs& args, DiarkisTransportType tt);
void OnPush(const DiarkisPushEventArgs& args, DiarkisTransportType tt);
void OnEcho(const DiarkisUdpEchoEventArgs& args);
void OnPing(const DiarkisUdpPingEventArgs& args);
std::vector<std::function<void()>> eventUnsubscriptions;
}
DiarkisUdpBase.cpp
#define REG_EVENT(__EVENT__, __LAMBDA__) this->eventUnsubscriptions.push_back(__EVENT__->Register(__LAMBDA__))
void DiarkisUdpBase::Setup(std::shared_ptr<LoggerFactory> loggerFactory, std::shared_ptr<ILoggerBackend> loggerBackend)
{
if (this->udp == nullptr)
{
this->udp.reset(DiarkisCreateUdp(200, 5000));
}
this->udp->SetLoggerFactory(loggerFactory);
this->fileAndDebugLoggerBackend = loggerBackend;
REG_EVENT(this->udp->GetConnectedEvent(), [this](void*, bool reconnect) { this->OnConnect(reconnect); });
REG_EVENT(this->udp->GetDisconnectedEvent(), [this](void*, bool reconnect) { this->OnDisconnect(reconnect); });
REG_EVENT(this->udp->GetResponseEvent(), [this](void*, const DiarkisResponseEventArgs& args) { this->OnResponse(args, DiarkisTransportType::UDP); });
REG_EVENT(this->udp->GetPushEvent(), [this](void*, const DiarkisPushEventArgs& args) { this->OnPush(args, DiarkisTransportType::UDP); });
REG_EVENT(this->udp->GetEchoEvent(), [this](void*, const DiarkisUdpEchoEventArgs& args) { this->OnEcho(args); });
REG_EVENT(this->udp->GetPingEvent(), [this](void*, const DiarkisUdpPingEventArgs& args) { this->OnPing(args); });
}
void DiarkisUdpBase::OnConnect(bool isReconnect)
{
// A connection is successfully established. Now you may interactive wit the server cluster
}