0

I'm looking at the .NET socket connect function in some code. http://msdn.microsoft.com/en-us/library/d7ew360f.aspx This function takes in a string as an argument that represents the name of the remote host.

My question is, how does the socket then go about getting the IP address of this remote host? Does it perform a DNS lookup or can it go to the Windows hosts file? (Windows XP)

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
mj_
  • 6,297
  • 7
  • 40
  • 80
  • I have a work for you regarding this post http://stackoverflow.com/questions/3481858/tutorial-on-how-to-drag-and-drop-item-from-uitableview-to-uitableview can you please contact me ? – Tariq Mar 12 '11 at 09:22

1 Answers1

1

Using Dns.GetHostAddresses(host);.

A fragment of the actual code is as follows:

public void Connect(string host, int port){
    // Checking parameters etc, removed.

     IPAddress[] addresses = Dns.GetHostAddresses(host);
     Connect(addresses,port);
}

So, the constructor with the hostname simply calls the constructor with the IP addresses.

See http://msdn.microsoft.com/en-us/library/system.net.dns.gethostaddresses.aspx for documentation about Dns.GetHostAddresses().

Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111