I guess that you have already restart Minecraft so if that doesn’t work, restart your system and see if it works for you.
Re-adding your friend is also one solution that you can try out. Remove the person that you want to connect with from your friend list and then add him/her back.
Solution 2: Change the settings
Navigate to the Xbox official website.
Now on the website, click the Xbox One/Windows 10 Online Privacy tab.
Now, find Join multiplayer games and you have to ensure that it should be set to Allow.
Set it to Allow if it is not and then click Submit.
Solution 3: Disable Antivirus
Antivirus may block certain features of the game. It happens with many applications that it gets block or some of the features get block by the antivirus. You can disable the antivirus for some time and then check if the error disappears or not.
If you're struggling to connect to a Minecraft server, there are a few things you can try: Restart your device. If you're on a wired connection, try connecting with a wireless connection or vice versa. Try connecting with another network connection if possible. try this once. HEB Partner
Check Your Connection. Restart Minecraft (and Your Computer) Check for Updates. Check for Windows Updates. Reload Your Private World. Change Your Firewall Settings. Remove and Re-add Your Friend. Update Drivers for Your Network Card.