Skip to content

Commit c80dafd

Browse files
committed
libraries/WiFi: Beginpacket function.
Signed-off-by: IFX-Anusha <[email protected]>
1 parent 553bd7e commit c80dafd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libraries/WiFi/src/WiFiUdp.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,23 @@ void WiFiUDP::stop() {
4141
}
4242

4343
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port) {
44-
return 0;
44+
remote_ip = ip;
45+
_port = port;
46+
return 1; // Return 1 if successful
4547
}
4648

4749
int WiFiUDP::beginPacket(const char *host, uint16_t port) {
50+
// Resolve the hostname to an IP address
51+
IPAddress ip;
52+
if (socket.hostByName(host, ip)) {
53+
return beginPacket(ip, port); // Call the IP-based version
54+
}
55+
56+
// Return 0 if hostname resolution fails
4857
return 0;
4958
}
5059

5160
int WiFiUDP::endPacket() {
52-
return 0;
5361
}
5462

5563
size_t WiFiUDP::write(uint8_t) {

0 commit comments

Comments
 (0)