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

  1. the method tries parse address. if hostnameoraddress parameter contains legal ip string literal, first phase succeeds.
  2. a reverse lookup using ip address of ip string literal attempted obtain host name. result set hostname property.
  3. the host name reverse lookup used again obtain possible ip addresses associated name , set addresslist property.

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -