So check the Firewall settings and ensure the Minecraft executable file “javaw.exe” is allowed in the Firewall. You can connect to the internet but can’t join each other’s world. If Minecraft is not allowed in the Firewall, the “Unable to connect to world” issue can happen. Somehow it works for many users on all platforms. Some players have reported that after reloading their private world, they’re able to connect to their friends’ world.
If you find you can still connect to a stranger’s world, you can remove the person as a friend then re-add him/her back.
There is one more thing you can try: re-add your friend. I believe you’ve already tried restarting Minecraft maybe even restart your computer. You may not have to try them all just work your way down the list until you find the one that works for you. If you don’t know whether your computer is powerful enough to run the game which may relate to this issue, you can check Minecraft system requirements first.
If you’re trapped by this problem, this post may help. It’s quite annoying when you try to connect with your friends’ worlds but receive this message “Unable to connect to world”.