![]() ![]() ![]()
|
SophiaFramework UNIVERSE 5.1 |


The SFXInetAddress class provides the Resolve function of converting a domain into an IP address. To manage a port number, use the SFXSocketAddress class.
How to use the SFXInetAddress class
Example 816. Method to resolve a domain
class MyClass {
SFXInetAddress _address;
Void Function(Void);
XALLBACK_DECLARE_SFXINETADDRESS(ResolveCallback)
};
Void MyClass::Function(Void)
{
SFCError error;
// set domain
if ((error = _address.Set("http://www.example.com/test"); == SFERR_NO_ERROR) {
// resolve domain( result will be notified to ResolveCallback function )
error = _address.Resolve(XALLBACK_INTERNAL(ResolveCallback));
}
if (error != SFERR_NO_ERROR) {
// handle error since ResolveCallback function will not be called
}
}
// callback function called after notified of the address resolution
XALLBACK_IMPLEMENT_SFXINETADDRESS(MyClass, ResolveCallback, error)
{
SInt16 i;
// get result
TRACE("%s",_address.Get().GetCString()); // domain
// repeat number of IP addresses
for(i = 0 ; i < _address.GetCount() ; i++){
// get result
TRACE("%s",_address.GetIP(i).GetCString()); // IP address
}
}
| Constructor/Destructor |
|---|
|
SFXInetAddress( Void ) Constructor of the SFXInetAddress class.
|
|
SFXInetAddress(
SFXInetAddressConstRef param
) Constructor of the SFXInetAddress class.
|
|
SFXInetAddress(
SFXAnsiStringConstRef param
) Constructor of the SFXInetAddress class.
|
|
SFXInetAddress(
INAddr inaddr
) Constructor of the SFXInetAddress class.
|
|
~SFXInetAddress( Void ) Destructor of the SFXInetAddress class.
|
| Public Functions | |
|---|---|
| static SFXInetAddress |
AnyInetAddress( Void ) Convert into the Any Address of the SFXInetAddress class.
|
| INAddr |
AsINAddr(
SInt16 index = 0
) Convert the IP address into the INAddr format.
|
| Void |
Cancel( Void ) Cancel the resolution of IP address.
|
| Void |
Clear( Void ) Make domain name empty.
|
| static SFXInetAddressConstRef |
EmptyInstance( Void ) Get an empty address.
|
| SFXAnsiStringConstRef |
Get( Void ) Get the domain.
|
| SInt16 |
GetCount( Void ) Get the number of IP addresses.
|
| SFXAnsiString |
GetIP(
SInt16 index = 0
) Get the IP address.
|
| static SFXInetAddress |
LocalInetAddress( Void ) Return the local IP address.
|
| static SFXInetAddress |
LoopbackInetAddress( Void ) Return the Loopback Address.
|
| SFCError |
Resolve(
CallbackSPP spp
, VoidPtr reference
) Resolve domain name.
|
| SFCError |
Set(
SFXInetAddressConstRef param
) Set the IP address and domain.
|
| SFCError |
Set(
SFXAnsiStringConstRef param
) Set the IP address and domain.
|
| SFCError |
Set(
INAddr inaddr
) Set the IP address and domain.
|
| SFXInetAddressRef |
operator=(
SFXInetAddressConstRef param
) Assign a domain IP address.
|
| Types |
|---|
|
CallbackSPP Type that represents the Callback function.
|
[ public, explicit ] SFXInetAddress(Void);
[ public ]
SFXInetAddress(
SFXInetAddressConstRef param // source SFXInetAddress
);
[ public, explicit ]
SFXInetAddress(
SFXAnsiStringConstRef param // domain character string
);
[ public, explicit ]
SFXInetAddress(
INAddr inaddr // IP Address
);
If the argument is of the SFXAnsiString::Set function, the domain string takes the following format:
<protocol> :// <account> @ <domain> : <port> / <path>
Only the <domain> part is taken out and set when the string with this format(it may be OK to lack some parts of the string) is given.
The IP address is automatically gotten by using the SFXInetAddress::AsINAddr function if the <domain> part is the IP address(string "nnn.nnn.nnn.nnn" ).
[ public ] ~SFXInetAddress(Void);
[ public, static ] SFXInetAddress AnyInetAddress(Void);
Return the Any Address (AEE_INADDR_ANY) of the SFXInetAddress class.
Get the IP address resolved using the SFXInetAddress::Resolve function in the INAddr format.
Since the SFXInetAddress instance holds several IP addresses in general, get the IP address by specifying its index.
To get the number of IP addresses, use the SFXInetAddress::GetCount function.
[ public ] Void Cancel(Void);
To cancel the callback function registered by the SFXInetAddress::Resolve function before called, use the SFXInetAddress::Cancel function.
This function releases the SFBNetMgr instance that is used in the SFXInetAddress::Resolve function.
[ public ] Void Clear(Void);
[ public, static ] SFXInetAddressConstRef EmptyInstance(Void);
Return an empty address of the SFXInetAddress class.
[ public, const ] SFXAnsiStringConstRef Get(Void);
[ public, const ] SInt16 GetCount(Void);
[ public, const ] SFXAnsiString GetIP( SInt16 index = 0 // index );
Get the IP address as a string (format: "nnn.nnn.nnn.nnn") resolved by the SFXInetAddress::Resolve function.
Since the SFXInetAddress instance holds several IP addresses, get an IP address by specifying its index.
To get the number of IP addresses held in the SFXInetAddress instance, use the SFXInetAddress::GetCount function.
[ public, static ] SFXInetAddress LocalInetAddress(Void);
Return the local IP address of the SFXInetAddress class.
The SFBNetMgr::GetMyIPAddr function is called internally.
[ public, static ] SFXInetAddress LoopbackInetAddress(Void);
Return the Loopback Address (AEE_BREW_LOOPBACK) of the SFXInetAddress class.
The SFXInetAddress::LoopbackInetAddress function is available for BREW 2.1 or over.
[ public ] SFCError Resolve( CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
The callback function specified with the argument is called after domain name is resolved. The callback function will not be called when an error occurs in the SFXInetAddress::Resolve function.
class MyClass {
SFXInetAddress _address;
Void Function(Void);
XALLBACK_DECLARE_SFXINETADDRESS(ResolveCallback);
};
Void MyClass::Function(Void)
{
SFCError error;
// set domain
if ((error = _address.Set("http://www.example.com/test"); == SFERR_NO_ERROR) {
// resolve domain( result will be notified to ResolveCallback function )
error = _address.Resolve(XALLBACK_INTERNAL(ResolveCallback));
}
if (error != SFERR_NO_ERROR) {
// handle error since ResolveCallback function will not be called
}
}
// callback function called after notified of the address resolution
XALLBACK_IMPLEMENT_SFXINETADDRESS(MyClass, ResolveCallback, error)
{
SFXAnsiString ip;
ip = _address.GetIP(0); // get result
}
[ public ] SFCError Set( SFXInetAddressConstRef param // source SFXInetAddress );
[ public ] SFCError Set( SFXAnsiStringConstRef param // domain character string );
[ public ] SFCError Set( INAddr inaddr // IP Address );
The domain string has the following format.
<protocol> :// <account> @ <domain> : <port> / <path>
Only the <domain> part is taken out and set when the string with this format(it may be OK to lack some parts of the string) is given.
The IP address is automatically gotten by using the SFXInetAddress::AsINAddr function if the <domain> part is the IP address(string "nnn.nnn.nnn.nnn" ).
The address resolution will be canceled if the SFXInetAddress::Set function is called while resolving.
SFXInetAddress address;
address.Set("http://www.example.com:80/test");
address.Get(); // "www.example.com"
SFXInetAddress address;
address.Set("127.0.0.1/test");
address.AsINAddr(); // return 127.0.0.1 in INAddr format
[ public ] SFXInetAddressRef operator=( SFXInetAddressConstRef param // source SFXInetAddress );
A specific format is recognized when the string of SFXAnsiString class is assigned.
The domain string takes the following format:
<protocol> :// <account> @ <domain> : <port> / <path>
Only the <domain> part is taken out and set when the string with this format(it may be OK to lack some parts of the string) is given.
The IP address is automatically gotten by using the SFXInetAddress::AsINAddr function if the <domain> part is the IP address(string "nnn.nnn.nnn.nnn" ).
typedef Void(* SFXInetAddress::CallbackSPP)(SFCError error, VoidPtr reference)
The SFXInetAddress::CallbackSPP function is the prototype for the callback function used in the SFXInetAddress class. The result of communication processing is notified to the callback function.
The error code is passed to the 1st argument, the parameter for the callback function is passed to the 2nd argument.
|
Copyright(c) 2002 - 2010 Sophia Cradle Incorporated All Rights Reserved. |
![]() ![]() ![]()
|