Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Networking Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.5 Using Internet Addresses

Internet addresses are the most popular socket address family. They identify communication endpoints on an internet, which is a network of computers that communicate using the TCP/IP suite of protocols. The "capital-I" Internet is the best known internet, but the Internet family of addresses is also used for thousands of smaller networks.

An internet address has two parts:

An internet address is represented in the Networking package as an RWInetAddr. As shown in Figure 10, an RWInetAddr object contains two objects: an RWInetHost to represent the host, and an RWInetPort to represent the port.

Figure 10: An RWInetAddr object

6.5.1 Constructing a Host

A host is identified by either a symbolic name, like net.roguewave.com, or by an Internet Protocol (IP) address, like 198.68.9.6. A particular host can have more than one symbolic name. A host address usually has only one IP address, although it is possible for a host to have more than one address.

You can construct a host object by specifying either the IP address or host name as a string, as shown in the following examples.

Once a host object is constructed, you can use the member functions of RWInetHost to determine characteristics of the host. For more information about RWInetHost, see the SourcePro C++ API Reference Guide.

Example 9 prints information about a host.

Example 9: Printing information about a host

//1

Returns a host object representing the host on which the program is running.

//2

Prints the primary symbolic name of the host.

//3

RWInetHost::getAddress() returns the four-byte IP address of the host. Usually, this address is printed a byte at a time using dotted decimal notation. The static function RWInetHost::addressAsString converts the address from a long integer to a string in dotted decimal format.

6.5.2 Building Internet Addresses

Example 10 shows how to build an Internet address object by specifying the port and then the host.

Example 10: Building internet addresses

//1

Includes both a port and a host. Automatic type conversion turns the integer 3010 into an RWInetPort, and turns the string into an RWInetHost.

//2

When the host name is omitted, the special host ANY is used. This address connects to any available IP address on the current computer.

//3

Sends the address as a string. The format is the socket type (stream or dgram), followed by the host identifier, followed by a port identifier. The fields are separated by colons. You can omit the socket type and host, which means that both net.roguewave.com:3010 and 3010 are allowed. The default socket type is stream. If only the port number is used, the host defaults to ANY.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.