The most common reason for that behavior is if your iPhone and your computer are connected to two different routers.
Do you have multiple routers in your local network? What is the Brand/Model of your modem? Sometimes modems have built-in routers.
If it's possible, try connecting the iPhone and the computer to the same router. If that isn't possible, you'll have to set the secondary router (router not directly connected to modem) to be in bridge mode. If you need help setting that up, please let me know the Brand/Model of your routers and let me know which one is primary (directly attached or integrated with modem) and which one is secondary (attached to the primary router).