Make sure both the devices are connected, and on the same network
Make sure you're not on a guest network
If both the PC and the phone are on Wi-Fi, you could check if both of them are on the same frequency (2 GHz vs. 5 GHz)
Modifying your Wi-Fi connection could help
On your phone, open your Wi-Fi settings
Find how to modify your saved Wi-Fi network (try a long-press on it)
Click advanced options
Change the IP settings from DHCP to Static
(After testing, you can revert to DHCP to go back to normal)
Choose an IP address (e.g.: 192.168.1.100)
Set the DNS value to 8.8.8.8
Save
Your router could be preventing devices from communicating between them. You could search for one of these terms in your router settings and deactivate the option if not needed: