Using Sockets

Team Fly 

Page 292

Aliases property This property returns (or sets) a list of aliases associated with a host.

HostName property This property returns (or sets) the friendly name of the host. The System.Net.Dns class exposes a few methods to manipulate computer addresses, which are:

GetHostByAddress(IPAddress) method This method accepts an IP address as argument and returns an IPHostEntry object. On my computer, the statement

      Console.WriteLine(GetHostByAddress(''127.0.0.1").HostName) 

returned the string "PowerToolkit." The GetHostByAddress method will return a hostname if the client with the specified address is on the same local network, or if it belongs to network with a registered name.

GetHostByName(hostname) method This method accepts a hostname as argument and returns the host's IP address. The following statement will return your computer's IP address, if you change the hostname to your computer's hostname:

      Console.WriteLine(System.Net.Dns.GetHostByName( _                         "myHost").AddressList(0)) 

If you're on a local area network and the Internet at the same time, the IPAddressList array will have multiple elements (multiple IP addresses).

Resolve(hostname) method This method accepts as argument an IP address or a hostname and returns an IPHostEntry object that represents the host. The argument can be either a friendly name (like "PowerToolkit" or "www.domain.com") or an IP address.

Now we can switch our attention to the classes for peer-to-peer programming, starting with the concept of sockets.

Using Sockets

At the lowest level, network programming consists of programming with sockets. Sockets are an old concept in network programming and they represent input points at a system, where a remote system can connect and make requests. There are many types of sockets, but the most common ones are the Internet sockets, because they deal with Internet addresses. Internet sockets come in two flavors: UDP (User Datagram Protocol) sockets (also known as Datagram sockets) and TCP (Transmission Control Protocol) sockets. The difference between the two is that UDP sockets are connectionless. Every time you need to send data using a UDP socket, a new connection to the remote machine is established. The connection is closed automatically when the data arrives at the remote machine. Every package of data is independent of the others, because it carries in its header all the information needed for its delivery.

TCP sockets require that a link between the two computers be established before they start exchanging data. The advantage of TCP sockets is that they're more reliable than UDP sockets. Packets sent through a UDP port may arrive in different order than the order in which they were sent. Moreover, a UDP packet may be lost without any indication. The sending machine will not receive a positive or

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net