GEOS SDK TechDocs|
|
|
2 Simple Example |
4 Making a Connection In the example above, the application queried the user for a connection address. This is a fairly common case. However, some programs need to use hard-wired addresses. Perhaps you want to allow connections over all available domains. Thus, a few words about addresses may be in order.
Addresses are usually represented via the
SocketAddress
structure:
typedef struct {
SocketPort SA_port;
word SA_domainSize;
char * SA_domain;
word SA_addressSize;
} SocketAddress;
/* domain-specific address data here */
SocketPort
structure, made up of a 16-bit
ManufacturerID
and 16-bit arbitrarily-chosen token number. If the domain uses 16-bit socket numbers, then use MANUFACTURER_ID_SOCKET_16BIT_PORT
as the
ManufacturerID
. If the domain allows 32-bit socket numbers, then you may use MANUFACTURER_ID_SOCKET_16BIT_PORT or some other
ManufacturerID
, probably your own ID or that of some standard service provider. This numbering scheme helps to avoid overlapping port numbers.
SocketAddress
structure,
SA_domain
is a pointer to the null-terminated domain name string and
SA_domainSize
is the size of the buffer containing the domain name string.
SocketGetDomain().
(See Letting the User Choose an Address.)
SA_addressSize
field of the
SocketAddress
structure contains the size of the address data. The buffer containing the address data should fall immediately after the
SocketAddress
structure. Read the documentation for a given domain to find out the format for its addresses.
SocketAddress
, that has the fields of
SocketAddress
, but also has a buffer to hold the resolved address data. More likely than not, you won't need to declare or define such a structure -- you're more likely to use
SocketCreateResolvedAddress()
or bypass the creation of this structure altogether.
Before using an address, make sure that it is in its primitive form. For instance, an IP address like "geoworks.com" is not in its primitive form -- the IP address must be translated into a four-byte number before it can be used. Use
SocketResolve()
(described below) to transform an address into its primitive form. Note that the address passed to
SocketResolve()
is not in a
SocketAddress
structure.
Letting the User Choose an Address
GEOS SDK TechDocs|
|
|
2 Simple Example |
4 Making a Connection