clientservervblssn3
Intro to TCP/IP  
 
Communications Section Week #3: Introduction to TCP/IP, Winsock and Interface Design This week introduces the student to commu

Essential TCP/IP Concepts

TCP/IP is the common language of the network world. These days, when computers need to talk to computers, it's a safe assumption that they will communicate using TCP/IP.

The TCP/IP protocols did not always display the exalted and omnipresent aura they show today. In the 1980s, TCP/IP was considered by many to be a nonstandard set of informal protocols that were found primarily in the esoteric realm of the Internet, an environment frequented by educators, computer wizards, and defense contractors. International standards bodies were developing official protocols that were expected to put TCP/IP out to pasture before too long.

Today, however, TCP/IP has become the dominant network protocol suite with hardly a viable competitor in sight, the international effort to establish competing protocols having died a quiet death. The difference has been the stodginess of the international standards process versus the vitality of the Internet. Indeed, the success of TCP/IP is a market-driven phenomenon, propelled by consumer demand and the desire to make a buck.

TCP/IP has become so dominant that sooner or later your network is going to need to talk TCP/IP, because sooner or later it is going to need to talk to another network—the Internet or some other—that talks only TCP/IP. That's good and bad; it's good because TCP/IP is an excellent protocol suite, offering good performance and use of network bandwidth. It's bad because until you are used to it, TCP/IP is a lot of trouble to set up and manage.

Until this chapter, you have been working in a Plug-and-Play world where network protocols are concerned. NetBEUI requires no configuration at all, whereas NWLink must be configured only when routing is required. There is so much to configuring TCP/IP, on the other hand, that you need a chapter of background information before you can even begin to set up TCP/IP on a network.

My intention is to keep things as simple and practical as possible. I'll have to give you some theory, but it will be theory that you will immediately put into practice, not theory that you will put into practice "someday."

Microsoft's TCP/IP Architecture

Microsoft has always had a somewhat unique way of organizing protocol suites. The architecture has been organized around two key requirements:

·         The need to support TCP/IP alongside NWLink and NetBEUI

·         The need to support NetBIOS applications in the TCP/IP environment

With the release of Windows 2000 Server, Microsoft has embraced a TCP/IP that does not require NetBIOS. However, this "native" mode for Windows 2000 Server can be used only if there are no legacy applications or clients that still require the NetBIOS layer.

One component of the network protocol architecture is NDIS, the Network Driver Interface Specification, which lets any network protocol communicate with any network adapter. NDIS lets all Windows 2000 protocols communicate through a single network adapter should the need arise.

Microsoft provides application programming interfaces (APIs) that developers use to adapt their programs to the network environment. Notice that Microsoft's architecture supports two APIs:

·         NetBIOS is the Network Basic Input/Output System, a fairly old API that has long been the primary API for applications running on Microsoft networks. Older applications written to network on Microsoft networks have been written to the NetBIOS API.

·         Windows Sockets (WinSock) is Microsoft's implementation of the sockets API that has become the primary API for TCP/IP applications. The applications you think of as Internet applications, such as Web browsers and FTP clients, are written for the Windows Sockets interface.

But that leaves a hole. What if I want to run only TCP/IP protocols on my network, but I don't want to abandon my venerable NetBIOS applications? Well, Microsoft has an answer for that as well, called NetBIOS over TCP/IP (NetBT or NBT for short). Thanks to NetBT, any Windows application can network over TCP/IP with no adaptation whatsoever.

Computer Addressing on TCP/IP Networks

TCP/IP predates just about all other networking standards that remain in common use. When the Internet was still a project of the United States Department of Defense and was named ARPAnet (for Advanced Research Projects Agency Network), the idea of a global network that embraced many different brands of computers was as exotic as interstellar travel. No one had formed even a fuzzy vision of how such a network might be implemented. So, the gurus had complete freedom to design a network solution. But freedom brings with it the opportunity to be unique, and some technologies on the Internet are definitely unique.

One unique characteristic of the Internet is the way computers are identified. The designers of the Internet protocols wanted an identification scheme that was independent of any one computer or network equipment design. So they established a scheme of IP addresses. (IP, or Internet Protocol, is one of the two most prominent TCP/IP protocols and is the protocol in the TCP/IP protocol suite that is most intimately concerned with addressing.)

You've almost certainly seen IP addresses—numbers such as 192.168.153.80—while surfing the Web. As you administer TCP/IP on your network, a considerable part of your time will be devoted to IP address assignment, because IP addresses don't just happen. They have to be entered manually into the configuration of each TCP/IP computer on your network. When a computer is added to your network, it needs an IP address. When it moves, it probably needs a new IP address.

So you have to understand how IP addresses work. Unfortunately, IP address rules are a bit subtle, and errors are common. I will hazard a guess that IP address misconfiguration will be the most common cause of difficulty you will experience with TCP/IP networking.

IP Addresses and Dotted-Decimal Notation

An IP address is really a pretty simple thing. It is a 32-bit binary like the following:

11001101101101110010001001101110

Did I say simple? How would you like to remember a few dozen of those? Well, even network gurus blanch at the thought of committing 32-bit numbers to memory, so they devised a system that codes IP addresses in more familiar binary numbers.

To display an IP address in decimal form, the first step is to break the binary address into four eight-bit fields, like this:

11001101 10110111 00100010 01101110

Each of these eight-bit fields—they're usually called octets, incidentally—can be represented by a decimal number in the range of 0 through 255.

To convert a binary number to decimal, examine each bit position. If the bit is a 1, the corresponding decimal number is included in the decimal total. If the bit is a 0, that bit does not affect the decimal total. Add up the decimal values corresponding to each 1 bit and you arrive at the decimal equivalent of the eight-bit binary number.

Fortunately, you don't need to convert more than eight bits, because IP addresses are commonly represented in dotted-decimal notation where a decimal number represents each eight-bit group.

IP Addresses and Dotted-Decimal Notation

An IP address is really a pretty simple thing. It is a 32-bit binary like the following:

11001101101101110010001001101110

Did I say simple? How would you like to remember a few dozen of those? Well, even network gurus blanch at the thought of committing 32-bit numbers to memory, so they devised a system that codes IP addresses in more familiar binary numbers.

To display an IP address in decimal form, the first step is to break the binary address into four eight-bit fields, like this:

11001101 10110111 00100010 01101110

Each of these eight-bit fields—they're usually called octets, incidentally—can be represented by a decimal number in the range of 0 through 255. Notice that each digit position corresponds to a power of 2. For example, the third digit from the right corresponds to 22, or 4.

To convert a binary number to decimal, examine each bit position. If the bit is a 1, the corresponding decimal number is included in the decimal total. If the bit is a 0, that bit does not affect the decimal total. Add up the decimal values corresponding to each 1 bit and you arrive at the decimal equivalent of the eight-bit binary number.

Fortunately, you don't need to convert more than eight bits, because IP addresses are commonly represented in dotted-decimal notation where a decimal number represents each eight-bit group.

Isn't that simple? Well, perhaps not. At least not simple enough to make the head math easy for most of us. Fortunately, Windows includes a shortcut. The Windows Calculator applet has a scientific mode that includes number base conversion functions.

To convert a number to another base, do the following:

1.      Open the Calculator applet and choose Scientific from the View menu.

2.      Select the radio button that matches the base of the number you want to convert (Hexadecimal, Decimal, Octal, or Binary).

3.      Enter the number to be converted. (You can paste a number you have copied from another application.)

4.      Select the radio button that matches the base you want to convert to (Hexadecimal, Decimal, Octal, or Binary). The result is displayed in the number entry field. (You can copy the results from Calculator and paste them elsewhere if you want.)

Although users see dotted-decimal addresses if they see addresses at all, as an administrator you must be aware of the binary equivalents of IP addresses. This is particularly the case when you get involved with subnet addressing, where the binary bit patterns are crucial information.

Address Classes

Each host on a TCP/IP network—host is another term for a device that is attached to a TCP/IP network—must have a unique IP address that distinguishes it from all other hosts on that network. That means that every host that can communicate with the Internet must have an IP address that is unique on the entire Internet.

Actually, a host's IP address contains two pieces of information:

·         netid is the network to which the host is attached.

·         hostid is the host's unique ID on its network.

Because the IP address serves two functions, the Internet designers had to decide how many bits of the IP address would serve as the netid and how many bits would serve as the hostid. Did the Internet need a few networks with many hosts per network, or did it need a large number of networks with few hosts per network? Well, the answer was "Both, and we need something in between as well." That answer resulted in the establishment of address classes.

You will encounter three address classes: A, B, and C. Class A defines a few networks, each of which can contain a vast number of hosts. Class C defines many networks, each of which can contain a couple hundred hosts. Class B falls somewhere between A and C.

 

The key differences between the classes are the numbers of bits that are allocated to the netid and hostid portions of the address. Here's how the address classes play out:

·         Class A addresses have eight bits in the netid portion and 24 bits in the hostid portion. There are 126 class A networks available, each of which accommodates 16,777,214 hosts. A class A address has a 0 for the initial bit, and the first octet will have a decimal value between 1 and 126. (Networks 0 and 127 have special uses.)

·         Class B addresses have 16 bits in the netid portion and 16 bits in the hostid portion. 16,384 class B networks are possible, each supporting 65,534 hosts. A class B address begins with the bits 10, and the value of the first octet falls in the range 128 through 191.

·         Class C addresses have 24 bits in the netid portion and eight bits in the hostid portion. Consequently, 2,097,152 class C network address begins with the bits 110, and the value of the first octet falls in the range 192 through 223.

If you take a close look at the bits and try to confirm my totals for netids and hostids, you'll find that the sums aren't what you might expect. That's because some bit patterns aren't available for hosts. Here are some restrictions:

·         Address 255 (all 1s in binary) is used to address broadcast messages, which are received by all hosts on a given network. The most common broadcast address is 255.255.255.255, which addresses messages that are to be received by all hosts on the local network.

·         The fourth octet cannot be all 1s or all 0s in binary. A hostid that is all 0s refers to this network. So, the IP address 155.38.0.0 refers to the entire network with the netid 155.38. A hostid that is all 1s is a broadcast address, referring to all hosts on a specific network.

·         The netid cannot be all 0s because all 0s means "this network." That's why the class A network number 0 is unavailable.

·         Netid 127 is a reserved address called the loopback address, and is used in testing.

Routers attach to the network as ordinary hosts. A router is assigned an IP address on each network to which it is attached. Actually, and this is an important distinction, the IP address isn't assigned to the router, but to the interface in the router. So, a router has at least two interfaces, each of which is assigned its own IP address.

Networks 172.16.0.0 and 172.17.0.0 were included to illustrate how class B and C netids work. Even though both networks have 172 as the first octet of their IP addresses, these are class B networks (first octet 128 through 192). Therefore, the netid is defined by two octets, and 155.38.0.0 and 155.39.0.0 function as separate network segments. Because a class C netid is defined by three octets, any differences in the first three octets of a class C address refer to different networks.

IP Address Assignment

If you are running a private TCP/IP network, you can choose any IP addresses you want for your hosts. If, on the other hand, your network will be connecting to the Internet, you must use assigned IP addresses that don't conflict with anyone else.

Until fairly recently, organizations requested IP addresses directly from the Internet Network Information Center (InterNIC), but that seldom happens these days because the Internet has simply grown too big for a single point of contact to handle the demand for access. The current practice for most organizations wanting to connect to the Internet is to obtain access from an Internet service provider (ISP) that provides an Internet hookup (for a fee, of course) and assigns a block of IP addresses. The InterNIC has actually been replaced by the Internet Assigned Numbers Authority (IANA), which prefers to work with a relatively few ISPs, assigning them blocks of addresses that they in turn allocate to their customers.

You can no longer obtain a class A or B address. In fact, class C addresses are scarce. Your ISP probably won't assign you a complete class C address unless you really need it. You might be given use of a portion of a class C address. Okay, so how do you use part of an address range? Thanks for asking, because the technique for subdividing address ranges is my next topic.

Subnet Addressing

As you might suspect, a class A or B address is a pretty big thing. It is difficult to imagine a network with 16 million hosts—or even 65,000 hosts—and not a single router, but that is what it would take to use up a class A or B address.

After it had an address space, the Internet community discovered that many of the IP address ranges were too large. A way was needed to subdivide the addresses so that portions of the address space could be allocated to multiple network segments. The mechanism designers arrived at is called subnet addressing.

We come now to one of the most challenging topics in this book. Many TCP/IP newbies find subnet addressing the highest hurdle they must clear, so don't be surprised if you find this material difficult. Just hang in there, and I'll make sure you get a grasp of the concept.

Subnet addressing is a method for "borrowing" bits from the hostid portion of an IP address so that the bits can be applied to the network ID.

Subnetting a Class B Address

Suppose that you have been assigned the Class B address 172.16.0.0. You need to create four separate networks from your one IP address range. The technique is to borrow three bits from the hostid field. These three bits let you configure six separate subnets. (Why not eight? I'll tell you later.)

To see how subnet addressing works, let's first convert the IP address to binary form:

10101100 00010000 00000000 00000000

Remember, in a class B address, the first 16 bits are the netid and the last 16 bits are the hostid.

To indicate that bits are being borrowed from the hostid, you use a subnet mask, which is also a 32-bit binary number. To make the purpose of the subnet mask clear, you need to examine it beside the binary IP address, like this:

10101100 00010000 00000000 00000000
11111111 11111111 11100000 00000000

The rules of subnet masking are extremely simple:

·         1 in the network mask indicates that a bit in the IP address is part of the netid.

·         0 in the network mask indicates that a bit in the IP address is part of the hostid.

Because there are 19 bits in the network mask, you now have 19 bits to work with in the netid. This lets you generate the following subnetwork IDs (subnetids) from the class B address:

10101100 00010000 00100000 00000000
10101100 00010000 01000000 00000000
10101100 00010000 01100000 00000000
10101100 00010000 10000000 00000000
10101100 00010000 10100000 00000000
10101100 00010000 11000000 00000000

Why only six subnets? You have to avoid two "forbidden" subnets (000 and 111), which are explained in an upcoming section.

If you do the math to convert the binary addresses to decimal, you find that the subnet mask 255.255.224.0 lets you construct six subnets with the following address ranges:

172.16.32.1 through 172.16.63.254

through 172.16.95.254

through 172.16.19.254

through 172.16.159.254

through 172.16.191.25

172.16.192.1 through 172.16.223.254

The subnet mask actually becomes part of the configuration of each host on the network, enabling the hosts to discriminate netid, subnetid, and hostid.

Take host 172.16.89.33, for example. Because this is a class B address, the netid consists of the first two octets and is 172.16. To figure out the subnetid, you need to apply the subnet mask to the third octet, which is binary 1011001. Here's the address octet next to the subnet mask:

10110001
11100000

So the subnetid portion is 101 and the hostid portion is 10001.

Which hosts can occupy the same subnet? The third octet for the subnet can have a value between 10100000 and 10111111, or between 160 and 191 decimal. In other words, any host with an IP address between 172.16.160.1 and 172.16.191.254 can be on the same subnet.

Netids, Subnetids, and Routers

To enable two hosts to communicate without a router, four conditions must be met:

·         The hosts must be connected to the same network segment

·         The host's IP addresses must have the same netid

·         The hosts must be configured with the same subnet mask

·         The hosts must have the same subnetid

Failing any of these conditions, a router is required to allow the hosts to communicate.

"Forbidden" Subnets

I've alluded a couple of times to the fact that some subnets are not permitted by the Internet standard that defines subnetwork addressing.

The first restriction applies to all TCP/IP implementations: the subnetid cannot consist entirely of 1s because addresses made up entirely of 1s are used to address broadcast messages.

A second restriction is that the subnetid cannot consist entirely of 0s. Actually, there really isn't a good reason to prohibit the all-0s subnet, and avoiding the all-0s subnet wastes valuable address space. So in practice many have chosen to support the all-0s subnets on their products. Windows 2000 permits use of the all-0s subnet, although I have never seen the fact stated in Microsoft documentation.

More Subnet Examples

Because it is so important for you to understand subnet addressing, look at some examples.

Example 1

Problem: For the IP address 10.86.45.3 and subnet mask 255.255.0.0, answer the following questions:

·         What is the netid of the IP address?

·         What is the subnetid of the IP address?

·         What is the hostid of the IP address?

·         What host IP addresses permit hosts to communicate directly with this host, assuming all hosts are connected to the same network segment?

Solution: The first step is to determine the class of the IP address. Because the first octet has the value 10, it is a class A address, and the netid consists of the first octet. Therefore, the netid is 10.

The subnet mask reserves 16 bits for the network address. The first eight bits are the netid, so the next eight bits, the entire second octet, make up the subnet ID. Now you know that the subnetid is 86.

The subnet mask leaves 16 bits for host addressing. Consequently, the hostid of this host is 45.3.

This host can communicate with hosts having IP addresses 10.86.0.1 through 10.86.255.254, assuming that all the hosts can communicate without crossing a router.

Example 2

Problem: For the IP address 192.168.45.109 and subnet mask 255.255.255.240, answer the following questions:

·         What is the netid of the IP address?

·         What is the subnetid of the IP address?

·         What is the hostid of the IP address?

·         What host IP addresses permit hosts to communicate directly with this host, assuming all hosts are connected to the same network segment?

Solution: Because the first octet has the value 192, this is a class C address, and the netid consists of the first three octets. Therefore, the netid is 192.168.45.

The subnet mask 11110000 reserves four bits for the network address. The fourth octet is 01101101 binary, making the subnetid 0110.

The subnet mask leaves four bits for host addressing. Consequently, the hostid of this host is 1101 decimal.

With this subnet mask, the fourth octet can have binary values 01100000 through 01101111. But a hostid cannot be all 0s or all 1s. Therefore, valid values for the fourth octet are 01100001 through 01101110. Consequently, this host can communicate with hosts having IP addresses 192.168.45.97 through 192.168.45.110, assuming that all the hosts can communicate without crossing a router.

Example 3

Problem: For the IP address 192.168.87.95 and subnet mask 255.255.255.224, answer the following questions:

·         What is the netid of the IP address?

·         What is the subnetid of the IP address?

·         What is the hostid of the IP address?

·         What host IP addresses permit hosts to communicate directly with this host, assuming all hosts are connected to the same network segment?

Solution: Because the first octet has the value 192, this is a class C address, and the netid consists of the first three octets. Therefore, the netid is 192.168.87.

The subnet mask 11100000 reserves three bits for the network address. The fourth octet is 01011111 binary, making the subnetid 010.

The subnet mask leaves five bits for host addressing. Consequently, the hostid of this host is 11111 decimal.

Oops, this was a trick question, wasn't it? Given that IP address and subnet mask, the netid is invalid because a netid cannot consist entirely of 1s. Now you can see why it is so important to dig down to the binary bare metal when you assign IP addresses. Unless you do, address errors are inevitable.

Trouble with Subnets

Subnet addressing is one area where network administrators are likely to encounter trouble. Suppose that a subnet contains the following hosts and uses the subnet mask 255.255.234.0:

172.16.161.80

172.16.180.153

172.16.192.209

172.16.177.44

Do you see a problem? Host 172.16.223.153 will be unable to communicate because it has a different subnetid from the other hosts. That isn't extremely obvious until you examine the binary values of the third octets (I've set out the subnet bits in bold type):

10100001
10110100
11000000
10110001

Oh, my! 172.16.192.209 is on another subnet, a fact you could easily miss if you relied on the dotted-decimal addresses.

Default Subnet Masks

A subnet mask is part of every host's configuration. What, even if no subnetting is taking place? Yes, always. When the network address isn't subnetted, the host is configured with a default subnet mask, in which the 1 bits match the standard netid bits for the class of the network class. If the network is using a class A address, for example, the default subnet mask is 255.0.0.0. Here are the default subnet masks:

·         Class A: 255.0.0.0

·         Class B: 255.255.0.0

·         Class C: 255.255.255.0

Subnets: Some Observations

Taking all the rules for subnetting into account, it appears that some subnet masks have more potential than others. After some discussion, I'll give you some tables that make it easy to evaluate the usefulness of various subnet options.

Take the subnet mask 128 (10000000), which in theory ought to permit you to set up two subnets. But one of those subnets would be the all-1s subnet, which is prohibited. So your payoff for giving up a bit of hostid is one subnet, exactly where you started off.

A subnet mask of 196 (11000000) gets you three subnets, not four as you might expect, again because the all-1s subnet isn't permitted. You only get three subnets because Microsoft permits use of the all-0s subnet.

Subnetting a class C address—yes, as small as it is, you might need to subnet a class C address if it is all you've got—has some special concerns because you have so few bits to work with. Suppose you are subnetting a class C address with the subnet mask 255.255.255.248. Here's the binary subnet mask:

11111111 11111111 11111111 11111000

The goal is to create a lot of subnetworks. Although you do in fact make it possible to configure 30 subnets, each subnet accommodates only six hosts! Besides resulting in itty-bitty subnets, you waste a lot of your potential addresses. A class C address can support a maximum of 254 hosts without subnetting. With the subnet mask 255.255.255.248, the same address supports only 180 hosts, 210 if you use the all-0s subnet. It is unfortunate that Internet address space has become so tight that it is necessary to subnet class C addresses, but it is often necessary to do so.

Tables 1, 2, and 3 summarize subnet options for class A, B, and C networks. Some options are marked "invalid" because they don't result in useful subnetwork configurations.

Table 1. Class A Subnetting

Subnet Bits

Maximum Subnets

Maximum Number of Hosts Per Subnet

Subnet Mask

0

0

16,777,214

255.0.0.0

1

invalid

invalid

invalid

2

2

4,194,302

255.192.0.0

3

6

2,097,150

255.224.0.0

4

14

1,048,574

255.240.0.0

5

30

524,286

255.248.0.0

6

62

262,142

255.252.0.0

7

126

131,070

255.254.0.0

8

254

65,534

255.255.0.0

 

Table 2. Class B Subnetting

Subnet Bits

Maximum Subnets

Maximum Number of Hosts Per Subnet

Subnet Mask

0

0

65,534

255.255.0.0

1

invalid

invalid

invalid

2

2

16,382

255.255.192.0

3

6

8,190

255.255.224.0

4

14

4,094

255.255.240.0

5

30

2,046

255.255.248.0

6

62

1,022

255.255.252.0

7

126

510

255.255.254.0

8

254

254

255.255.255.0

 

Table 3. Class C Subnetting

Subnet Bits

Maximum Subnets

Maximum Number of Hosts Per Subnet

Subnet Mask

0

0

254

255.255.255.0

1

invalid

invalid

invalid

2

2

62

255.255.255.192

3

6

30

255.255.255.224

4

14

14

255.255.255.240

5

30

6

255.255.255.248

6

62

2

255.255.255.252

7

invalid

invalid

255.255.255.254

8

invalid

invalid

255.255.255.255

 

Computer Names on Microsoft TCP/IP Networks

Networked computers are identified by numbers. On TCP/IP networks IP numbers identify them. On NWLink and NetBEUI networks numbers defined by the underlying network such as Ethernet identify them. But the rule is the same: to send a message to another device, a computer must know the numeric ID of the destination device. But people hate referring to computers by numbers, particularly the long numbers commonly used to identify network computers, so it has long been the practice of network designers to provide a mechanism that identifies computers by names. Ideally, computer naming should be completely transparent, requiring no intervention on the part of users and little on the part of network administrators. People use the names, and in the background computers figure out the numbers they require to communicate.

To meet those goals in the past, Microsoft based its network products on NetBIOS names, which were cataloged by a browser service. The NetBIOS name was the name you entered into the computer's configuration when you installed the operating system. The Browser service collected the NetBIOS names of all servers on the network. With the release of Windows 2000 Server, however, Microsoft now offers pure TCP/IP network browsing, using conventions such as Domain Name Service (DNS) and Lightweight Directory Access Protocol (LDAP).

Backward compatibility

For backward compatibility with network clients running earlier versions of Windows that support only NetBIOS naming, Microsoft has retained some services that allow these clients to find resources on the network.

 

LMHOSTS Files

An LMHOSTS file is a text file, maintained using any text editor that maps host names to IP addresses. A typical entry in an LMHOSTS file looks like this:

192.168.143.8   Drew

Each computer must have an LMHOSTS file that contains an entry for each server. That sounds simple, but it turns out to be a significant administrative hassle.

You see, someone must not only update the LMHOSTS file, but also take responsibility for ensuring that a fresh copy is distributed to every computer every time a change takes place in the network configuration. That's fine on small networks that seldom change, but it's a recipe for indigestion on a large or dynamic network.

Windows Internet Naming Service

So Microsoft needed a dynamic service that would keep itself up-to-date, and it came up with the Windows Internet Naming Service or WINS. The WINS system consists of one or more WINS servers that maintain copies of the network name database. Clients register their NetBIOS names and addresses with WINS. And when a client needs to communicate with a server, it queries WINS for the server's address.

WINS appears to solve the NetBIOS-to-TCP/IP translation problem. As clients enter the network, WINS is automatically appraised of any changes. That's better than LMHOSTS files. After WINS is configured, it can be pretty much ignored by the administrator. And, because all WINS communication takes place through directed messages, routers don't interfere with WINS operation.

There's only one problem with WINS. Nobody but Microsoft used it. Everyone else uses Internet-based naming systems, as Windows 2000 Server does natively. So you need to look at the Internet side of things next.

Computer Names on the Internet

The Internet faces a problem much like the problem Microsoft solved with NetBIOS names, LMHOSTS, and WINS. Users cannot remember more than a few IP addresses, so they need names.

As with Microsoft's approach, two techniques have been used to simplify host naming on TCP/IP networks: HOSTS files and the Domain Name Service.

HOSTS Files

HOSTS files works just like LMHOSTS files. They are text files with entries that match host names with IP addresses. An entry in a HOSTS file looks like this:

192.168.143.8   drew ws1 blivets99

An entry in a HOSTS file isn't that different from an entry in LMHOSTS except that a HOSTS file lets a host have more than one name, called an alias. (Also, LMHOSTS files have some special features specific to the Microsoft environment.)

HOSTS files have the same disadvantages cited for LMHOSTS files. They are tedious and, because each host must receive a new copy each time the file is updated, HOSTS files are time-consuming to maintain and distribute. Consequently, most TCP/IP administrators rely on the Domain Name Service to provide name resolution support.

Domain Name Service

Like WINS, the Domain Name Service (DNS) deploys servers that can be queried by network clients to resolve names to IP addresses.

The DNS name database is big, and it can be distributed in chunks across many, many name servers. On a network as big as the Internet, it would be inefficient to maintain the complete database on one computer. For one thing, the computer would be overwhelmed with the data and with servicing name resolution queries. For another, a single database would be impossible to maintain because every organization would need to submit name changes to a central authority, a bureaucratic nightmare when millions of organizations are involved. The Internet needed a naming system that let each organization maintain its own chunk of the database. DNS meets that goal. It is expandable without limit, and it permits local control of portions of the database.

In order to allow Microsoft networks to run as purely DNS-managed, Microsoft has implemented a dynamic DNS, which acts much like its WINS service.

The Microsoft DNS server has three distinct advantages:

·         Entries can be modified interactively through a graphic interface.

·         It isn't necessary to restart a Microsoft DNS Server to activate database changes.

·         The Microsoft DNS Server can obtain names from WINS, allowing it to keep pace with the dynamic Windows naming environment.

Routing

TCP/IP routing is also a bit more involved than anything you have seen so far in the book. The only thing you need to do to configure routing with NWLink is to install RIP for NWLink. With TCP/IP you have two options: static routing and RIP.

Static Routing

Static routing makes use of a static routing database that resides on each computer. You maintain some entries in the static routing table using entries in the Network applet in the Control Panel. Other entries are managed using the route command-line utility.

Every TCP/IP computer has a static routing table. An important entry in the static routing table is the default router. If a host doesn't know where to send a message, it will send the message to its default router, which is presumed to know how to deliver the message to its final destination.

All TCP/IP routing can be handled through static routing, but it can be a hassle to maintain static routing when the network configuration changes frequently. On large networks it is more common to use a dynamic routing protocol such as the Routing Information Protocol.

Routing Information Protocol

You have already encountered a version of the Routing Information Protocol (RIP) that is used to configure routers for NWLink. Microsoft includes RIP for TCP/IP with Windows 2000 Server.

RIP is a dynamic routing protocol that updates routing tables based on information exchanged with other RIP routers. The dynamic nature of RIP lets routers update their routing tables as the network configuration changes. RIP, or another dynamic routing protocol, is deployed on most large TCP/IP networks because the task of maintaining static routing tables would be overwhelming.

Virtual Private Networking

A virtual private network (VPN) is a mechanism for providing secure, encrypted communications in two configurations. First, a user to network configuration, where the remote user connects to the Internet and using a VPN is able to securely become a node on the company network. This is commonly referred to as the "Remote Access" model for a VPN. The other configuration is when a site/office uses the VPN coupled with an Internet connection to securely connect to the network at the other end of the VPN. This is commonly referred to as a site-to-site VPN. The remote access VPN is used to supplant the standard remote access of dial-in or authenticated firewall access to the network. The site-to-site model is being used in places to remove the need for a wide area network. Windows 2000's VPN services can support both models.

Both configurations offer significant cost savings over the more traditional access methods. One downside of the VPN model, however, is during Internet backbone outages. When you are unable to connect to your office because one of the Tier 1 networks has suffered a fiber cut, whom can you call? With a WAN or a remote access solution you always had a vendor you could call for a status or to have a technician dispatched. There is no 1-800-INTERNET number that you can call for technical support. This is the major tradeoff with a VPN solution versus a more traditional approach.

The methods of utilizing the Winsock control to allow Visual Basic applications to communicate over the Internet

To compile an application means that Visual Basic translates the application and all its projects into an executable file. You’ll want to compile your application for these reasons:

·        Your application will load and run faster.

·        Your user won’t need the Visual Basic development environment to run the application.

·        The application is more secure because compiled programs are more difficult to change than uncompiled source code such as that which you run inside the development environment.

When you compile your project, Visual basic gathers all the project files together and converts those files in to a single executable file. The executable file has the .exe filename extension, and your users can run the application from the Start menu’s Run option or from an entry they add to the Start menu.

To compile your application, select File| Make and select a location from the Make Project dialog box that appears. When you click OK, Visual Basic compiles the program. You can now exit Visual Basic and run the program from the Start menu’s Run command.

Setting Project Properties

Before you a compile a program, you can take a moment to set some project properties that determine how the program compiles when you click the Options button in the Make Project dialog box.

Version control refers to the capability of Visual Basic to assign version numbers, such as 1.01, 1.02, 2.00, and so on, to compiled code.

If you plan to update your application in the future and distribute subsequent versions, set the Major, Minor, and Revision version number text boxes. The versioning values let you distinguish between compiled versions. You might want to place the version number in your application’s Help| About dialog box.

In addition to the versioning information, consider locating an icon that you want displayed on the Start menu and on the taskbar that represents your program. The only catch is that you cannot set the application’s icon from the Icon list box. The Icon list box lets you select a form name from your project. If your project contains only a single form, that’s the only form that appears in the list box. The form’s Icon property holds the icon filename, and when you select that form in the Project Properties dialog box, its icon becomes the compiled application’s icon. When you click the Project Properties dialog box’s Compile tab, you’ll be able to set additional properties.

Generally, if you go to the trouble of compiling the application, you’ll want to make sure the option labeled Compile to Native Code is selected. If you compile as p-code using the top option, your application will run more slowly and require a runtime .dll file that you must distribute along with your application.

P-code is an interpreted language that works beneath some compiled Visual Basic applications. P-code, which stands for pseudo code, tells the system what your application wants to do next. Native Code, on the other hand, is a machine language that your computer understands directly without the need for a time-consuming interpreted language such as p-code. Versions of Visual Basic before 5.0 could not compile applications into native code, so programmers had to use p-code. P-code still exists for compatibility, but you’ll always want to compile into native code for the fastest execution speed your application can achieve.

By clicking the Advanced Optimizations command button, you display another set of options. There is one problem with this set of options: Although they produce a more efficient running application, the application checks less for runtime errors. You will want to set one or more of these advanced options only if you have thoroughly tested your application.

Setting Up Your Application

The Package And Deployment Wizard is a wizard that turns your compiled application into a complete installation disk set.

After you test and compile your application, you are ready to create the distribution set of files that your user uses to install the application. Visual Basic supplies the Package And Deployment Wizard to help you turn your application into distributable disks.

Not every application should be installed from disks, and the Package And Deployment Wizard creates a distribution set for just about any kind of installation, such as for CD-ROM installations and for networked computer users who want to install the application from a server. Actually, the Package And Deployment Wizard performs several tasks, including the following:

·        Compresses files so your installation’s disk files consume less space than the installed application

·        Generates an uninstall configuration so that the users who install your applications can remove your application and all its related files at a later date

·        Creates a disk set of installation files, even spreading extra-large files over multiple disk volumes if needed

·        Generates a setup program for users who install the application

·        Generates a hard disk installation set so that you can copy the setup application onto a CD-ROM or install the application over a network to other users

·        Creates a special setup distribution so that you or other users can install the application across the Internet

Starting the Package And Deployment Wizard

After you compile your application, you can distribute it by starting the Application Setup Wizard from the Windows Start menu. Locate the Start menu from which you normally start Visual Basic, but instead of starting Visual Basic, start the program named Package And Deployment Wizard to display the wizard’s opening dialog box. The Package And Deployment Wizard is likely going to be found in the Tools folder of the Visual Studio Start menu folder. Click the Browse button to select the Visual Basic project you want to distribute. The Package And Deployment Wizard offers you the following options:

·        By selecting the Package button, you can generate a setup program and, optionally, set up a dependency file to ensure that needed files are included with you application. These needed files might be ActiveX control files or help files. Although all your forms and code compile into an executable, several external files and resource files.

·        If you will be deploying your distribution file to a distribution such as an Internet server, click the Deploy button.

·        Use the Manage Scripts button to make modifications to Package And Deployment Wizard scripts that you have already created.

For most applications, you will be distributing for the immediate future, so you will select the Package button. After selecting a project, press the Package button to proceed with this lesson.

The Package And Deployment Wizard must know exactly which files to include with the installed set of disks. Even though the Setup Wizard installs your application’s executable, the Package And Deployment Wizard must search your application’s project file to get a list of all related files.

A dependency file is a reference file that determines which files are needed by other files. For example, an application might require an ActiveX control to execute, and that ActiveX control would be a dependency file for the application.

If the Visual Basic project you selected has not yet been compiled, the Package And Deployment Wizard will give you the chance to compile it before proceeding any further. You will then be asked to select a Package type for the distribution package. Choose to create a Standard Setup Package.

When prompted, select the folder in which the distribution package will be assembled. The VB Package And Deployment Wizard will then analyze your application and determine which other files should be distributed with your application so that it executes properly. Until you are more familiar with what various files selected by the Package And Deployment Wizard for distribution do, leave all the selected files the same and proceed to the next dialog box.

The Package And Deployment Wizard will prompt you for the distribution type with the dialog box. The Distribution Type dialog box tells the Package And Deployment Wizard how to build the setup program. The Single File option installs the setup routine to a single hard disk file, which you then could copy to a CD-ROM. The Multiple Files option is ideal for installing the setup files onto one or more floppy disks. When the dialog box appears, use it to give the installation program a title. It is a good idea to include your application’s version number here along with the title. The dialog box is used to select a start menu group and an icon for your application. If you want, you can make modifications to the default values.

In the next dialog box, the Package And Deployment Wizard will give you the opportunity to modify the individual location of various individual files in the distribution package. After examining the default locations, proceed to the next dialog box. It is recommended that you do not change the default location (System32 folder) of shared DLL files. For most applications that you will be building in the immediate future, you can leave the same default options of subsequent dialog boxes.

Depending on various other capabilities of your applications (database access, for example), you might see additional Package And Deployment Wizard dialog boxes. Finally, the Package And Deployment Wizard will give you the option of saving the settings you specified for this project in a script file. This will make things easier for you the next time you want to use the Package And Deployment Wizard to create a distribution file for a newer version of the same project. After specifying a script name, click the Finish button and sit back and watch the Package And Deployment Wizard perform its magic.

Make sure that you test your setup installation to ensure that the installed application performs the way you expect. If you forgot a dependency or didn’t even know your application required one, your installed application won’t run correctly. You then can begin to trace the problem, such as adding an ActiveX control file to the dependency list if the control is missing. To run the installation, select the Start menu’s Run command, click Browse to locate the Setup.exe file, and click OK.

The installation routine won’t overwrite existing files on the target computer if the target computer already has newer files that have the same filename. If the installation routine finds such as a file, the routine will ask the user for permission to overwrite the current file or leave the newer file intact. Most of the time the user should leave the existing files to preserve newer versions of their software, especially ActiveX controls.

An uninstall routine removes the application, including all related files, from the computer. One of the best features of the setup routine is its ability to create an uninstall routine for the application. To uninstall the application, select Settings| Control Panel from the Windows Start menu and double-click the Add/Remove Programs icon. Your installed application will appear in the list of applications available for removal. Click the Add/Remove command button, and the uninstall process begins.

Online Visual Basic

Visual Basic 6 makes Internet access extremely simple. An intranet is a localized version of the Internet and is sometimes used as a local area network’s protocol system. You can use Visual Basic’s internet connections to build routines and applications that access both the Internet and your own company’s intranet. The intranet is becoming the interface of choice by many companies whose employees access the Internet. After all, shouldn’t the computer down the hall from you be as simple to access as a computer around the world? Instead of using a separate networking software solution, many companies prefer to leverage their existing Internet tools. You’ll be able to build simple intranet applications with Visual Basic by the time you finish this lesson. You must have Microsoft’s Internet Explorer 3.0 or later installed on your system before you can create Visual Basic applications with Internet access.

One of the wizard’s dialog boxes gives you access to the Internet. Try it yourself by following these steps:

1.      Start a new project.

2.      From the New Project dialog box, double click VB Application Wizard to start the wizard.

3.      Read the dialog boxes and click Next as you follow the wizard’s application design. Accept all the default values on each dialog box and pause when you come to the dialog box labeled Internet Connectivity.

A Web browser is a program that lets you display and interact with colorful Web pages on the Internet. URL (uniform resource locator) is an Internet Web site address where you can point a Web browser. URLs generally begin with http:// (which stands for Hypertext Transfer Protocol). URL addresses can also specify an FTP (File Transfer Protocol) document or even another document that resides on your computer or on another networked disk.

4. Click Yes to request Internet support. In addition, enter a default URL in the text box. If you don’t change the default URL, the Web browser will go to Microsoft’s home page when the application’s user displays the web browser the first time.

If your company has a home page, you might want to enter that home page’s URL in the text box. If you want to make your users really smart, point them to Macmillan Publishing’s home page at http://www.mcp.com.

5.      When you complete the Internet dialog box, continue clicking Next until you get to the final wizard dialog box. Click Finish to complete the wizard and watch the wizard generate your application.

Close the wizard’s summary dialog boxes and run the application. Obviously, something is wrong because the application doesn’t look anything like an Internet application. When you ran the wizard, you accepted a lot of dialog box default values. The wizard didn’t generate an Internet application only, but rather an application that happens to contain Internet through your Internet Service Provider.

An ISP is an Internet service that you and your users use to connect to the Internet. You might even work for a company that contains the hardware needed to be its own ISP. If your PC has Internet access, you’ll have no trouble using the application you create. Therefore, when you distribute your application, if the application has Internet access, you’ll need to warn the users that they, too, must have an ISP to use the application with the Internet. Again, if your users are workers within your own company that already provides Internet access to PCs, you’ll have no problems distributing your applications.

When you select View| Web Browser with your generated application, your application will attempt to make an Internet connection through your ISP. Generally, this means that you’ll have to log on to the Internet by issuing your username and password. For example, if you subscribe to the Internet using The Microsoft Network online service, you’ll Sign In dialog box right after you select View| Web Browser. Obviously, anyone who runs your application must also log in to her ISP, and her ISP login dialog box will appear in place of this Sign In dialog box if she uses a different ISP. After you log in to the ISP, the application displays the Web browser and the Web page you set as the default.

The Web browser includes the standard browsing tools that you are used to if you’ve ever used a browser. You can perform all the following tasks from your application’s browser:

·        You can click the Web page’s hotspots to jump to related Web pages.

·        You can enter a new URL in the Address text box to see a different site.

·        You can browse backward through the pages you’ve seen by clicking the toolbar’s Back button.

·        Once you back up, you can return to a Web page by clicking the toolbar’s Forward button.

·        If a Web page takes a long time to load its graphics, you can click the toolbar’s Stop button to freeze the page at its current loaded state.

·        You can refresh a Web page that you’ve stopped from loading or refresh to see new information by clicking the toolbar’s Refresh button.

·        The toolbar’s Home button takes you to the home page set up for your ISP. You can select View| Options| Navigation to set a different home page.

·        Click the toolbar’s Search button to locate other sites on the Internet.

All this possible and your never coded one programming statement to gain the Internet functionality!

Looking Through the Other Tools

When you select Project| Components and look through the list of tools you can add to the Toolbox window, you’ll find several Internet-related tools. For example, all the controls that begin with the words Internet Explorer are Internet Explorer-like controls you can add to an application.

Winsock

Winsock is the Windows interface to inter-computer data communication. You’ll also find several FTP and Winsock controls that help you encapsulate advanced Internet applications into packages you can use as a standalone Web browser or, more commonly, as a Web browser you can make available in the idle of your application for your application’s users to use when needed.

Using the Winsock Control

A WinSock control allows you to connect to a remote machine and exchange data using either the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP). Both protocols can be used to create client and server applications. Like the Timer control, the WinSock control doesn't have a visible interface at run time.

Possible Uses

·                     Create a client application that collects user information before sending it to a central server.

·                     Create a server application that functions as a central collection point for data from several users.

·                     Create a "chat" application.

Selecting a Protocol

When using the WinSock control, the first consideration is whether to use the TCP or the UDP protocol. The major difference between the two lies in their connection state:

·                     The TCP protocol control is a connection-based protocol, and is analogous to a telephone — the user must establish a connection before proceeding.

·                     The UDP protocol is a connectionless protocol, and the transaction between two computers is like passing a note: a message is sent from one computer to another, but there is no explicit connection between the two. Additionally, the maximum data size of individual sends is determined by the network.

The nature of the application you are creating will generally determine which protocol you select. Here are a few questions that may help you select the appropriate protocol:

1.                  Will the application require acknowledgment from the server or client when data is sent or received? If so, the TCP protocol requires an explicit connection before sending or receiving data.

2.                 Will the data be extremely large (such as image or sound files)? Once a connection has been made, the TCP protocol maintains the connection and ensures the integrity of the data. This connection, however, uses more computing resources, making it more "expensive."

3.                 Will the data be sent intermittently, or in one session? For example, if you are creating an application that notifies specific computers when certain tasks have completed, the UDP protocol may be more appropriate. The UDP protocol is also more suited for sending small amounts of data.

Setting the Protocol

To set the protocol that your application will use: at design-time, on the Properties window, click Protocol and select either sckTCPProtocol, or sckUDPProtocol. You can also set the Protocol property in code, as shown below:

Winsock1.Protocol = sckTCPProtocol

Determining the Name of Your Computer

To connect to a remote computer, you must know either its IP address or its "friendly name." The IP address is a series of three digit numbers separated by periods (xxx.xxx.xxx.xxx). In general, it's much easier to remember the friendly name of a computer.

To find your computer's name

1.                  On the Taskbar of your computer, click Start.

2.                 On the Settings item, click the Control Panel.

3.                 Double-click the Network icon.

4.                 Click the Identification tab.

5.                 The name of your computer will be found in the Computer name box.

Once you have found your computer's name, it can be used as a value for the RemoteHost property.

TCP Connection Basics

When creating an application that uses the TCP protocol, you must first decide if your application will be a server or a client. Creating a server means that your application will "listen," on a designated port. When the client makes a connection request, the server can then accept the request and thereby complete the connection. Once the connection is complete, the client and server can freely communicate with each other.

The following steps create a rudimentary server:

To create a TCP server

1.                  Create a new Standard EXE project.

2.                 Change the name of the default form to frmServer.

3.                 Change the caption of the form to "TCP Server."

4.                 Draw a Winsock control on the form and change its name to tcpServer.

5.                 Add two TextBox controls to the form. Name the first txtSendData, and the second txtOutput.

6.                 Add the code below to the form.

7.                        Private Sub Form_Load()
8.                            ' Set the LocalPort property to an integer.
9.                            ' Then invoke the Listen method.
10.                       tcpServer.LocalPort = 1001
11.                        tcpServer.Listen 
12.                        frmClient.Show ' Show the client form.
13.                    End Sub
14.                     
15.                    Private Sub tcpServer_ConnectionRequest _
16.                    (ByVal requestID As Long)
17.                        ' Check if the control's State is closed. If not, 
18.                        ' close the connection before accepting the new
19.                        ' connection.
20.                       If tcpServer.State <> sckClosed Then _
21.                        tcpServer.Close
22.                       ' Accept the request with the requestID 
23.                       ' parameter.
24.                       tcpServer.Accept requestID
25.                   End Sub
26.                    
27.                    Private Sub txtSendData_Change()
28.                       ' The TextBox control named txtSendData 
29.                       ' contains the data to be sent. Whenever the user 
30.                       ' types into the  textbox, the  string is sent 
31.                        ' using the SendData method.
32.                       tcpServer.SendData txtSendData.Text
33.                   End Sub
34.                    
35.                   Private Sub tcpServer_DataArrival _
36.                   (ByVal bytesTotal As Long)
37.                        ' Declare a variable for the incoming data. 
38.                       ' Invoke the GetData method and set the Text
39.                       ' property of a TextBox named txtOutput to 
40.                       ' the data.
41.                        Dim strData As String
42.                       tcpServer.GetData strData
43.                       txtOutput.Text = strData
44.                   End Sub

The procedures above create a simple server application. However, to complete the scenario, you must also create a client application.

To create a TCP client

1.                  Add a new form to the project, and name it frmClient.

2.                 Change the caption of the form to TCP Client.

3.                 Add a Winsock control to the form and name it tcpClient.

4.                 Add two TextBox controls to frmClient. Name the first txtSend, and the second txtOutput.

5.                 Draw a CommandButton control on the form and name it cmdConnect.

6.                 Change the caption of the CommandButton control to Connect.

7.                  Add the code below to the form.

Important   Be sure to change the value of the RemoteHost property to the friendly name of your computer.

Private Sub Form_Load()
    ' The name of the Winsock control is tcpClient.
    ' Note: to specify a remote host, you can use 
    ' either the IP address (ex: "121.111.1.1") or
    ' the computer's "friendly" name, as shown here.
    tcpClient.RemoteHost = "RemoteComputerName"
    tcpClient.RemotePort = 1001
End Sub
 
Private Sub cmdConnect_Click()
    ' Invoke the Connect method to initiate a 
    ' connection.
    tcpClient.Connect
End Sub
 
Private Sub txtSend_Change()
    tcpClient.SendData txtSend.Text
End Sub
 
Private Sub tcpClient_DataArrival _
(ByVal bytesTotal As Long)
    Dim strData As String
    tcpClient.GetData strData
    txtOutput.Text = strData
End Sub

The code above creates a simple client-server application. To try the two together, run the project, and click Connect. Then type text into the txtSendData TextBox on either form, and the same text will appear in the txtOutput TextBox on the other form.

Accepting More than One Connection Request

The basic server outlined above accepts only one connection request. However, it is possible to accept several connection requests using the same control by creating a control array. In that case, you do not need to close the connection, but simply create a new instance of the control (by setting its Index property), and invoking the Accept method on the new instance.

The code below assumes there is a Winsock control on a form named sckServer, and that its Index property has been set to 0; thus the control is part of a control array. In the Declarations section, a module-level variable intMax is declared. In the form's Load event, intMax is set to 0, and the LocalPort property for the first control in the array  is set to 1001. Then the Listen method is invoked on the control, making it the "listening control. As each connection request arrives, the code tests to see if the Index is 0 (the value of the "listening" control). If so, the listening control increments intMax, and uses that number to create a new control instance. The new control instance is then used to accept the connection request.

Private intMax As Long
 
Private Sub Form_Load()
   intMax = 0
   sckServer(0).LocalPort = 1001
   sckServer(0).Listen
End Sub
 
Private Sub sckServer_ConnectionRequest _
(Index As Integer, ByVal requestID As Long)
   If Index = 0 Then
      intMax = intMax + 1
      Load sckServer(intMax)
      sckServer(intMax).LocalPort = 0
      sckServer(intMax).Accept requestID
      Load txtData(intMax)
   End If
End Sub

UDP Basics

Creating a UDP application is even simpler than creating a TCP application because the UDP protocol doesn't require an explicit connection. In the TCP application above, one Winsock control must explicitly be set to "listen," while the other must initiate a connection with the Connect method.

In contrast, the UDP protocol doesn't require an explicit connection. To send data between two controls, three steps must be completed (on both sides of the connection):

1.                  Set the RemoteHost property to the name of the other computer.

2.                 Set the RemotePort property to the LocalPort property of the second control.

3.                 Invoke the Bind method specifying the LocalPort to be used. (This method is discussed in greater detail below.)

Because both computers can be considered "equal" in the relationship, it could be called a peer-to-peer application. To demonstrate this, the code below creates a "chat" application that allows two people to "talk" in real time to each other:

To create a UDP Peer

1.                  Create a new Standard EXE project.

2.                 Change the name of the default form to frmPeerA.

3.                 Change the caption of the form to "Peer A."

4.                 Draw a Winsock control on the form and name it udpPeerA.

5.                 On the Properties page, click Protocol and change the protocol to UDPProtocol.

6.                 Add two TextBox controls to the form. Name the first txtSend, and the second txtOutput.

7.                  Add the code below to the form.

8.                        Private Sub Form_Load()
9.                            ' The control's name is udpPeerA
10.                       With udpPeerA
11.                            ' IMPORTANT: be sure to change the RemoteHost 
12.                            ' value to the name of your computer.
13.                            .RemoteHost= "PeerB" 
14.                            .RemotePort = 1001   ' Port to connect to.
15.                            .Bind 1002                ' Bind to the local port.
16.                        End With
17.                        frmPeerB.Show                 ' Show the second form.
18.                    End Sub
19.                     
20.                   Private Sub txtSend_Change()
21.                        ' Send text as soon as it's typed.
22.                       udpPeerA.SendData txtSend.Text
23.                   End Sub
24.                    
25.                   Private Sub udpPeerA_DataArrival _
26.                   (ByVal bytesTotal As Long)
27.                        Dim strData As String
28.                       udpPeerA.GetData strData
29.                       txtOutput.Text = strData
30.                   End Sub

To create a second UDP Peer

1.                  Add a standard form to the project.

2.                 Change the name of the form to frmPeerB.

3.                 Change the caption of the form to "Peer B."

4.                 Draw a Winsock control on the form and name it udpPeerB.

5.                 On the Properties page, click Protocol and change the protocol to UDPProtocol.

6.                 Add two TextBox controls to the form. Name the TextBox txtSend, and the second txtOutput.

7.                  Add the code below to the form.

8.                        Private Sub Form_Load()
9.                            ' The control's name is udpPeerB.
10.                       With udpPeerB
11.                            ' IMPORTANT: be sure to change the RemoteHost 
12.                            ' value to the name of your computer.
13.                            .RemoteHost= "PeerA"
14.                            .RemotePort = 1002    ' Port to connect to.
15.                            .Bind 1001                ' Bind to the local port.
16.                        End With
17.                    End Sub
18.                     
19.                    Private Sub txtSend_Change()
20.                       ' Send text as soon as it's typed.
21.                        udpPeerB.SendData txtSend.Text
22.                   End Sub
23.                    
24.                   Private Sub udpPeerB_DataArrival _
25.                   (ByVal bytesTotal As Long)
26.                       Dim strData As String
27.                        udpPeerB.GetData strData
28.                       txtOutput.Text = strData
29.                   End Sub

To try the example, press F5 to run the project, and type into the txtSend TextBox on either form. The text you type will appear in the txtOutput TextBox on the other form.

About the Bind Method

As shown in the code above, you must invoke the Bind method when creating a UDP application. The Bind method "reserves" a local port for use by the control. For example, when you bind the control to port number 1001, no other application can use that port to "listen" on. This may come in useful if you wish to prevent another application from using that port.

The Bind method also features an optional second argument. If there is more than one network adapter present on the machine, the LocalIP argument allows you to specify which adapter to use. If you omit the argument, the control uses the first network adapter listed in the Network control panel dialog box of the computer's Control Panel Settings.

When using the UDP protocol, you can freely switch the RemoteHost and RemotePort properties while remaining bound to the same LocalPort. However, with the TCP protocol, you must close the connection before changing the RemoteHost and RemotePort properties.

What is an Internet Application?

Simply put, an Internet application is an interactive, compiled application that can be accessed through a corporate intranet or through the Internet. Internet applications can perform complex business processes on either the client or the server. In a server-based Internet application, the application uses the HTTP Internet protocol to receive requests from a client, typically a Web browser, process associated code, and return data to the browser.

In Visual Basic Internet programming, you can add active content to Web pages with little effort. Visual Basic Internet applications link Visual Basic code to one or more HTML pages and handle events raised in those pages by interacting with programs on either a client or a server. There are two types of Internet applications in Visual Basic: server-based IIS applications and client-based DHTML applications.

The user interface in a Visual Basic Internet application can be a series of HTML pages, a mix of HTML pages and Visual Basic forms, or a Visual Basic form that makes use of special components such as the WebBrowser control to take advantage of some of the power of the Internet. Regardless of the type of user interface, the application handles events, calls methods, and sets and retrieves properties based on elements in the HTML page.

The Web pages that make up the user interface for Visual Basic Internet applications are generally produced by a Web designer, rather than a developer. If you prefer to create your own HTML pages you can, but you do not have to. Instead, you can focus on your talents as a Visual Basic programmer by writing Visual Basic code that interacts with and uses HTML. Using your skills as a developer, you can easily produce dynamic, powerful applications for the Web.

For example, using Visual Basic Internet technology, you might create an application that can be used entirely on the browser to let salespeople track their status on the road, then link up to the central server when they return to the office. Or, you might create a sophisticated database-driven system that presents a catalog of selections to your end users, through their browser. Users could choose products from the catalog and your application would run associated Visual Basic code to retrieve product detail from a database recordset and send that information to the user.

Understanding Internet Basics

You can program for the Web, using your skills as a Visual Basic programmer, no matter what your level of experience with Internet technology. If you are new to the Internet or unfamiliar with its technology, Visual Basic allows you to quickly and easily produce functional applications. If you are more experienced with Internet technology, you can work at a more advanced level.

From one perspective, Internet technology simply provides another area for your development efforts. When you deploy Internet applications on the Web, you may go about it differently — incorporating HTML pages with your Visual Basic code, providing security features, and so on — but you're still calling methods, setting properties, and handling events. In this way, all of your knowledge as a Visual Basic developer can be carried into the Internet arena.

From another perspective, applying Internet technology enables you to extend your development skills in exciting new ways. For example, writing Visual Basic code that manipulates HTML pages allows you to decrease deployment costs, reduce client maintenance problems, and reach the broad audience of the Internet.

Internet Clients and Servers

A common way to think about Internet development is in terms of client/server relationships. In this case, the client is the browser, and the server is the Web server. Most interactions on the Internet or an intranet can be thought of in terms of requests and responses. The browser makes a request to the Web server (usually to display a page the user wants to see) and the Web server returns a response (usually an HTML page, an element, or an image) to the browser.

Internet vs. Intranet

The Internet encompasses two categories: the Internet and the intranet. The Internet is a global, distributed network of computers operating on a protocol called TCP/IP. An intranet is also a network of computers operating on the TCP/IP protocol, but it is not global. Generally, intranets are restricted to a particular set of users and are not accessible by the outside world. For example, many corporations use a corporate intranet to provide information to their employees, and run another Internet site for external users. Users within the company can access both the intranet sites and the Internet, but users outside the company can access only the company's Internet sites.

A History of Development on the Internet

Visual Basic programming technology represents a new set of approaches to Web technology, focused on the Visual Basic developer. This section offers a brief history of the Web's evolution from linked static content to the dynamic, compiled environment of Visual Basic Internet applications.

Static Content

The first applications on the Internet consisted of static pages that delivered their content to the browser and did not react dynamically to any actions the user performed. Although this model provides ready access to nicely formatted pages of information for your employees or potential customers, it provides limited interaction between the user and the Web server — and the static pages have to be manually edited to update their content.

Dynamic Content through Gateway Programming

The development of gateway interfaces such as Common Gateway Interface (CGI), Internet Server Application Programming Interface (ISAPI), and others allowed users to add dynamic content to the Web. With dynamic content, a browser can send a request for information. The server, instead of returning a static page, runs a script or application and returns HTML that reflects up-to-date, accurate information.

The disadvantage of gateway programs is that they are difficult to create and change. Gateway programs are not integrated into HTML files; in fact, they require an entirely different design process than do HTML files. In addition, all processing in a gateway program happens entirely on the server. This can increase server load and lead to backlogs in processing.

Scripting

Scripting enables dynamic content by embedding executable scripts directly in an HTML page. Rather than querying the server for an executable, the browser can process scripts as it loads the HTML page. These scripts can be processed on either the client or the Web server. The most common languages for client-side scripting are VBScript and JavaScript. A common framework used for server-side scripting is called Active Server Pages, or ASP.

In the ASP scripting model, HTML development and scripting development are part of the same process. This translates into tangible benefits, enabling Web providers to provide interactive business applications rather than merely publishing content. For example, a travel agency can go beyond just publishing flight schedules; it can use ASP scripting to enable customers to check available flights, compare fares, and reserve a seat on a flight.

With ASP scripting, you can use any scripting language for which an appropriate scripting engine is available. ASP supplies scripting engines for Microsoft Visual Basic Scripting Edition (VBScript) and Microsoft JScript. You can incorporate sophisticated functionality using ActiveX components to process data and generate useful information.

Visual Basic Internet Applications

Visual Basic Internet technology takes the process one step further by allowing you to link standard Visual Basic code to a user interface of HTML pages. This provides an extremely powerful mechanism for associating programming functionality with your Web pages, while allowing you to create dynamic, interactive content. With Visual Basic Internet technology, you can perform complex business operations while avoiding some of the intricacies of gateway programming or scripting. You can also enjoy all the benefits of working in Visual Basic, such as using class modules, controls, and designers, and debugging your code.

There are two main types of Visual Basic Internet applications: IIS applications and DHTML applications:

IIS applications, named for Microsoft Internet Information Server, reside on a Web server and are used to process incoming requests from a browser. IIS applications process the requests, run associated Visual Basic code, and return responses to the user. All processing for an IIS application happens on the server.

DHTML applications, named for Dynamic HTML, let you write Visual Basic code that handles events on any element of an HTML page. Most processing in a DHTML application can happen on the browser computer, although the application can make calls to the server if necessary.

DHTML applications require the end user to have Microsoft Internet Explorer version 4.0 or later, while IIS applications are browser- and operating system—independent to the end user. Because of this, IIS applications are the appropriate choice when you want to develop an application that reaches a broad audience. DHTML applications may be the more appropriate choice for intranet applications or applications that need to support remote or offline usage.

There are also other types of applications you can create in Visual Basic that make use of the Internet. For example, you can create ActiveX components that can be used on the Internet. These include ActiveX controls that can be used on Web pages, ActiveX documents that can run in a browser, and ActiveX code components that can be deployed on a Web server for behind-the-scenes processing. In addition, you can use the WebBrowser control to use HTML pages within a forms-based application.

Advantages of Visual Basic Internet Applications

There are many ways to develop applications for the Internet. Prior to Visual Basic 6.0, developers relied on CGI programs, on ActiveX functionality, or on Active Server Pages to create dynamic, interactive Internet applications. Internet application development in Visual Basic offers several key advantages over those approaches:

You can greatly reduce the cost of deployment per user. End users of an IIS Internet application can run the application using only a browser; no special software aside from the appropriate browser needs to be installed on their computers. End users of a DHTML Internet application need only the appropriate browser and the Visual Basic run-time on their computers. These necessary pieces are installed automatically.

You can leverage your knowledge of Visual Basic and use the Visual Basic programming environment. You do not have to learn scripting or manipulate HTML tags to develop a highly functional Web-based application.

You can separate designing the user interface from writing the code for a form or page. In previous Web-based applications, developers had to insert their script directly into an HTML document that was also used to generate the user interface. The end result was code that could be difficult to read and maintain.

In IIS applications, you can reuse pages in different contexts. Unlike HTML, where information to move from page to page must be embedded in the HTML itself, navigation information for a page in a Visual Basic Internet application is stored separately from the page itself. This allows you to reuse the page in several places in your application, changing the navigation each time depending on the context.

You can lessen download time and therefore reduce your network load, because the system does not need to download large components to run the application.

You can easily maintain application state, such as the user's name or account number, between client requests. Depending on the type of application, you can manage state on the client, the server, or both.

You can debug your IIS and DHTML applications using Visual Basic's standard debugging tools. Script and CGI-based Internet applications, on the other hand, can be very difficult to debug.

Other Internet Technologies in Visual Basic

In addition to DHTML applications and IIS applications, there are other types of Internet functionality you can add to your projects in Visual Basic, including:

ActiveX components that can be used on HTML pages, either as part of an IIS or DHTML application or not. ActiveX components include controls, code components, and ActiveX documents. Using some or all of these solutions, you can create highly functional Internet solutions for your business needs.

Internet extensions for Visual Basic applications. You can use special controls that provide some Internet-related functionality. These include the Internet Transfer control, the WebBrowser control, and the WinSock Control.

ActiveX Controls

ActiveX controls enliven and add power to your HTML pages. In addition to creating your own controls, you can use the Internet controls provided with the Professional and Enterprise editions of Visual Basic to extend standard applications with Internet technology. For example, you can use ActiveX controls on a Web page to add customized menus to your Web pages, add a scrolling banner you can use to present advertisements or important announcements, or add animated effects.

Using HTML and VBScript, you can include ActiveX controls on an HTML page, set their properties, call their methods, and handle their events.

For More Information   See the "Building ActiveX Controls" chapter in the "Creating ActiveX Components" book of the Component Tools Guide for information on developing ActiveX controls for your Visual Basic applications.

ActiveX Code Components

You can use ActiveX code components (.dll or .exe files) to add functionality to an HTML page on either the client or server. Code components on the client can offer an increase in speed, since users' commands do not need to be routed back to the server. Server components also have the benefit of being able to show user interface elements.

For More Information   See the "Creating an ActiveX DLL," "Creating an ActiveX EXE Component," or "Building Code Components" chapters in the "Creating ActiveX Components" book of the Component Tools Guide for information on developing ActiveX components for your Visual Basic applications.

ActiveX Documents

ActiveX documents integrate tightly with the other elements of your Internet or intranet site. You can use ActiveX documents in conjunction with DHTML applications, IIS applications, or HTML pages that are not associated with a Visual Basic Internet application. You can deploy these components so that users can navigate transparently between ActiveX documents and other pages in your application or Web site.

You might use ActiveX documents within your Internet applications for two reasons:

If you need to use the Visual Basic programming model rather than the programming model used in DHTML or IIS applications.

If you want to have control over the whole frame of the browser window, rather than just a part of it. When you display a Web page in the browser, the HTML you write to display the page lets you specify the appearance of only the page itself. You cannot write HTML to control the menu, the scroll bar, or any other part of the browser window. When you use an ActiveX document, you can control additional pieces of the window: You can add menus, toolbars, scroll bars, and other items. For example, if you want one page of your DHTML application to contain a custom menu, you might use an ActiveX document.

As is the case with the elements of an HTML page, ActiveX documents that are not installed on users' computers can be automatically downloaded when users navigate to them — and upgraded automatically if the versions on the server are more recent.

For More Information    See the "Building ActiveX Documents" chapter in the "Creating ActiveX Components" book of the Component Tools Guide for information on creating an ActiveX document.

Internet Extensions for Standard Applications

The Professional and Enterprise Editions of Visual Basic also include controls designed specifically to encapsulate Internet-related technology. These include:

Internet Transfer Control — Packages three common Internet protocols: HyperText Transfer Protocol (HTTP), File Transfer Protocol (FTP), and Gopher.

WinSock Control — Allows you to connect to a remote computer and exchange data using either the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP).

In addition, a WebBrowser control that is available when you install Internet Explorer 4.x allows you to run Web pages as part of a Visual Basic form.

 

My Quia activities and quizzes
Client/Server Development and Remote Data Lesson 3 Quiz: session quiz3clientservervb
https://www.quia.com/quiz/575549.html
Lesson 3 Quiz
Useful links
Last updated  2008/09/28 00:54:31 PDTHits  894