c# - foreach over DNS host addresses -
i have code:
iphostentry host = null; socket sock; host = dns.gethostentry("ip.."); foreach (ipaddress address in host.addresslist) { ipendpoint ipe = new ipendpoint(address, 7777); sock = new socket(ipe.addressfamily, sockettype.stream, protocoltype.tcp); sock.connect(ipe); if (sock.connected) { sock.sendto(encoding.utf8.getbytes("hello world"), ipe); } }
this code works ok on localhost, when write vps ip, code not working, what's problem?
it seem dns set incorrectly , dns.gethostentry(string)
fails @ second point below. if dns server fails reverse lookup won't return hostname, dns.gethostentry(string)
doesn't know , return empty address list.
from msdn: https://msdn.microsoft.com/en-us/library/ms143998.aspx
- the method tries parse address. if hostnameoraddress parameter contains legal ip string literal, first phase succeeds.
- a reverse lookup using ip address of ip string literal attempted obtain host name. result set hostname property.
- the host name reverse lookup used again obtain possible ip addresses associated name , set addresslist property.
Comments
Post a Comment