问题
I deployed a .NET Windows Service on Azure Virtual Machine running Windows Server with an opened port that allow me to connect to it, this service is like a server using socket. The problem is that when I try to connect from my PC to that hosted server it doesn't work and I get this exception: System.Net.Sockets.SocketException: 'No such host is known'
. The port is opened and visible from my PC. Can someone tell me why I get that exception? If I run locally all works ok.
回答1:
The Exception seems to be a DNS issue. I am not familiar with C#, from networking, you could check the followings on your side:
Windows service is running and the port is listening on the Azure VM.
The port is allowed for outbound traffic from your PC and Inbound traffic on your Azure VM. Check the VM firewall settings on both sides between your PC and Azure VM. Also, you could check the NSG settings follow this. You could use
telnet vmpublicIP port
on your PC CMD to verify network connectivity.- Verify your PC can resolve the address of hosted server if you connect it via its DNS name. You could use the
NSlookup
orDIG
to verify this. If it's DNS issue, you also could add a line in hosts file (located in%WINDIR%\system32\drivers\etc
on windows) mapping the hosted server's IP to a name.
Hope this helps.
来源:https://stackoverflow.com/questions/53982007/net-service-system-net-sockets-socketexception-no-such-host-is-known