99 * - Starts processing the next available incoming packet, checks for the presence of a UDP packet
1010 * - Reads the packet and checks if the data is correct.
1111 * - Receives multiple packets from different senders and checks if the data and IP are correct.
12- * - Handles packet loss by not sending a packet
1312 * - Writes a packet to the client
13+ * - Handles packet loss by not sending a packet
14+ * - Joins a multicast group and receives a packet from it
1415 * - Stops the UDP server
1516 * - Disconnect from the client and stop the access point.
1617 *
@@ -121,6 +122,25 @@ TEST_IFX(wifi_udp_server, handle_packet_loss)
121122 TEST_ASSERT_EQUAL_INT (0 , udpServer.parsePacket ());
122123}
123124
125+ TEST_IFX (wifi_udp_server, joinmulticast_receive)
126+ {
127+ IPAddress multicastIP (239 , 0 , 0 , 1 );
128+ uint16_t port = 1234 ;
129+
130+ udpServer.stop (); // Stop any previous instance
131+ TEST_ASSERT_TRUE (udpServer.beginMulticast (multicastIP, port));
132+
133+ const char * expected_msg = " Hello, Multicast!" ;
134+ char rcvd_msg[50 ] = {0 };
135+
136+ int packetSize = 0 ;
137+ while ((packetSize = udpServer.parsePacket ()) != (int )strlen (expected_msg)) {}
138+ TEST_ASSERT_EQUAL_INT (strlen (expected_msg), packetSize);
139+ udpServer.read ((uint8_t *)rcvd_msg, packetSize);
140+ TEST_ASSERT_EQUAL_STRING (expected_msg, rcvd_msg);
141+ }
142+
143+
124144TEST_IFX (wifi_udp_server, udp_server_end)
125145{
126146 udpServer.stop ();
@@ -144,6 +164,7 @@ TEST_GROUP_RUNNER(wifi_udp_server) {
144164 RUN_TEST_CASE (wifi_udp_server, receive_multiple_packets);
145165 RUN_TEST_CASE (wifi_udp_server, udp_server_write);
146166 RUN_TEST_CASE (wifi_udp_server, handle_packet_loss);
167+ RUN_TEST_CASE (wifi_udp_server, joinmulticast_receive);
147168 RUN_TEST_CASE (wifi_udp_server, udp_server_end);
148169 RUN_TEST_CASE (wifi_udp_server, wifi_disconnect);
149170 RUN_TEST_CASE (wifi_udp_server, wifi_end);
0 commit comments