Add error recovery when UDP transfer fails
This commit does not affect normal case. Even if UDP transfer fails for any reasons in sendNTPPacket, it can be recovered by re-initialization.
This commit is contained in:
parent
6645bf44e8
commit
079cdafe0f
@ -201,7 +201,11 @@ void NTPClient::sendNTPPacket() {
|
|||||||
this->_udp->beginPacket(this->_poolServerIP, 123);
|
this->_udp->beginPacket(this->_poolServerIP, 123);
|
||||||
}
|
}
|
||||||
this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE);
|
this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE);
|
||||||
this->_udp->endPacket();
|
if (this->_udp->endPacket() == 0) {
|
||||||
|
// recovery if UDP client encounters any errors
|
||||||
|
this->end();
|
||||||
|
this->begin(this->_port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTPClient::setRandomPort(unsigned int minValue, unsigned int maxValue) {
|
void NTPClient::setRandomPort(unsigned int minValue, unsigned int maxValue) {
|
||||||
|
Loading…
Reference in New Issue
Block a user