Quick Question About UDP Stuff (noob)

I have a quick question, if i set something to recieve udp packets on port 'a', and i do the same for another device, but they are connected to different wifi networks, do they still both recieve the messages, or do they have to be same port on same network? Like, i want to use the esp8266 wifi library and wifiudp library but all examples show them connecting to wifi first then listening on udp. Do they have to be same network and same port, or just same port nd bare minimum have to nbe connected to any network?

UDP runs on top of IP. So, the packet needs to be send to both devices separately. If the are in the same network both devices will have a different IP address and if they are in different networks the IP packet needs to be routed to them, so from your senders perspective they still have different IP addresses, even if the local IP address is the same.

The simples case is for all your devices to be in the same network.

The port is simply a way to identify the protocol for which the data is intended. Many ports have been defined for standard protocols like HTTP port 80, NTP port 123 … So, the port alone does not allow the data to be send to a specific device. That is what the IP protocol handles.