.NET TCP/IP Sockets API

TCP/IP is a suite of protocols designed to make a network manageable. The main protocols in it are the Internet Protocol (IP), the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). TCP/IP is organized into two layers, network and transport. The IP network layer and the TCP and UDP transport layers which function above the IP layer. Machines, or hosts, use the IP layer to transport data to and from one another via IP addresses. Both TCP and UDP are application protocols and use port numbers to allow multiple applications in each host to be identified. Ports range from 1 to 65535. TCP detects and recovers from the reordering, losses and duplications inherent in IP's host-to-host communication. UDP does not; it simply extends the datagram service of the IP. Applications that use UDP must manage reordering, losses and duplications on their own. Finally, an application uses the UDP and TCP protocols through the sockets API.

The sockets API is a way through which an app can send and receive data. Reading and writing to sockets is somewhat like reading and writing to files. Sockets were originally created for the Berkeley Software Distribution of UNIX and later a version was adapted to Microsoft Windows.

Resolve DNS Entries

Convert a DNS entry to its IP Addresses, Canonical Name, and Aliases:

string GetHostInfoHtml()
{
	StringBuilder sb = new StringBuilder();
	try
	{
		IPHostEntry hostinfo = Dns.Resolve("www.dell.com");
		sb.Append("<p><b>Canonical Name:</b> ");
		sb.Append(hostinfo.HostName);
		sb.Append("<br /><b>Aliases:</b> ");
		foreach (string s in hostinfo.Aliases)
		{
			sb.Append(s);
			sb.Append(" ");
		}
		sb.Append("<br /><b>IP Addresses:</b> ");
		foreach (IPAddress ia in hostinfo.AddressList)
		{
			sb.Append(ia.ToString());
			sb.Append(" ");
		}
		sb.Append("</p>");
	}
	catch (Exception ex)
	{
		sb.Append("<p><b>");
		sb.Append(ex.Message.ToString());
		sb.Append("</b></p>");
	}
	return sb.ToString();
}
Host Lookup using Sockets
<< < [Page 1 of 3] > >>