@@ -18,47 +18,38 @@ WiFiUDP::WiFiUDP() :
18
18
_port(0 ) {
19
19
}
20
20
21
- uint8_t WiFiUDP::begin (uint16_t port) {
22
- // Initialize the socket for UDP
21
+ uint8_t WiFiUDP::beginInternal (uint16_t port, IPAddress multicastIP ) {
22
+
23
23
socket.begin (SOCKET_PROTOCOL_UDP);
24
24
if (socket.status () != SOCKET_STATUS_CREATED) {
25
25
return 0 ;
26
26
}
27
27
28
28
socket.setReceiveOptCallback (receiveCallback, this );
29
29
30
- // Bind the socket to the specified port
31
30
socket.bind (port);
32
31
if (socket.status () != SOCKET_STATUS_BOUND) {
33
32
return 0 ;
34
-
35
- }
36
- return socket.status (); // Return the socket status
37
- }
38
-
39
- uint8_t WiFiUDP::beginMulticast (IPAddress ip, uint16_t port) {
40
- // Initialize the socket for UDP
41
- socket.begin (SOCKET_PROTOCOL_UDP);
42
- if (socket.status () != SOCKET_STATUS_CREATED) {
43
- return 0 ;
44
33
}
45
34
46
- socket.setReceiveOptCallback (receiveCallback, this );
47
-
48
- // Bind the socket to the specified port
49
- socket.bind (port);
50
- if (socket.status () != SOCKET_STATUS_BOUND) {
51
- return 0 ;
35
+ if (multicastIP != IPAddress (0 , 0 , 0 , 0 )) {
36
+ IPAddress local_ip = WiFi.localIP (); // Get the local IP address
52
37
38
+ // Bind the socket to the specified multicast address and port
39
+ cy_rslt_t result = socket.joinMulticastGroup (multicastIP, local_ip);
40
+ udp_assert_raise (result);
53
41
}
54
42
55
- IPAddress local_ip = WiFi.localIP (); // Get the local IP address
43
+ return socket.status (); // Return the socket status
44
+ }
56
45
57
- // Bind the socket to the specified multicast address and port
58
- cy_rslt_t result = socket.joinMulticastGroup (ip, local_ip);
59
- udp_assert_raise (result);
46
+ uint8_t WiFiUDP::begin (uint16_t port) {
47
+ // Start the UDP socket on the specified port
48
+ return beginInternal (port, IPAddress (0 , 0 , 0 , 0 ));
49
+ }
60
50
61
- return socket.status (); // Return the socket status
51
+ uint8_t WiFiUDP::beginMulticast (IPAddress ip, uint16_t port) {
52
+ return beginInternal (port, ip);
62
53
}
63
54
64
55
void WiFiUDP::stop () {
0 commit comments