SophiaFramework UNIVERSE 5.3 |
The SFXInetAddress class provides functions such as managing domain and/or IP address or resolving domain to IP address
Tip | |
---|---|
To manage port number other than domain and/or IP address, use the SFXSocketAddress class. |
How to use the SFXInetAddress class
Note | |
---|---|
There is no need to resolve domain with the SFXInetAddress::Resolve function when an IP address is specified with the SFXInetAddress::SFXInetAddress constructor or the SFXInetAddress::Set function. |
Example 823. Method to resolve domain
class MyClass { SFXInetAddress _address; Void Function(Void); XALLBACK_DECLARE_SFXINETADDRESS(ResolveCallback) }; Void MyClass::Function(Void) { SFCError error; // set domain name if ((error = _address.Set("http://www.example.com/test"); == SFERR_NO_ERROR) { // resolve domain name(result of domain name resolution will be notified to the ResolveCallback function) error = _address.Resolve(XALLBACK_INTERNAL(ResolveCallback)); } if (error != SFERR_NO_ERROR) { // if an error occurs, the ResolveCallback function will not be called // error handling ... } } // callback function notified of result of domain name resolution XALLBACK_IMPLEMENT_SFXINETADDRESS(MyClass, ResolveCallback, error) { SInt16 i; // display domain name on BREW Output window TRACE("%s",_address.Get().GetCString()); // repeat number of IP addresses for(i = 0 ; i < _address.GetCount() ; i++){ // display IP address on BREW Output window TRACE("%s",_address.GetIP(i).GetCString()); } }
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 ) Get INADDR_ANY of the SFXInetAddress type.
|
INAddr |
AsINAddr(
SInt16 index = 0
) Get the IP address of the INAddr type from this object.
|
Void |
Cancel( Void ) Cancel to resolve the domain name.
|
Void |
Clear( Void ) Clear the domain name or IP address setting of this object.
|
static SFXInetAddressConstRef |
EmptyInstance( Void ) Get an empty address.
|
SFXAnsiStringConstRef |
Get( Void ) Get the domain name of the SFXAnsiString type from this object.
|
SInt16 |
GetCount( Void ) Get the number of IP addresses from this object.
|
SFXAnsiString |
GetIP(
SInt16 index = 0
) Get the IP address of the SFXAnsiString type from this object.
|
static SFXInetAddress |
LocalInetAddress( Void ) Get the IP address of the local host or device.
|
static SFXInetAddress |
LoopbackInetAddress( Void ) Get the loopback address of the SFXInetAddress type.
|
SFCError |
Resolve(
CallbackSPP spp
, VoidPtr reference
) Resolve the domain name.
|
SFCError |
Set(
SFXInetAddressConstRef param
) Set the specified domain name or IP address to this object.
|
SFCError |
Set(
SFXAnsiStringConstRef param
) Set the specified domain name or IP address to this object.
|
SFCError |
Set(
INAddr inaddr
) Set the specified domain name or IP address to this object.
|
SFXInetAddressRef |
operator=(
SFXInetAddressConstRef param
) Assign the specified address of the SFXInetAddress type.
|
Types |
---|
CallbackSPP Type that represents the callback function.
|
[ public, explicit ] SFXInetAddress(Void);
[ public ] SFXInetAddress( SFXInetAddressConstRef param // source SFXInetAddress );
[ public, explicit ] SFXInetAddress( SFXAnsiStringConstRef param // domain name );
[ public, explicit ] SFXInetAddress( INAddr inaddr // IP Address );
If a domain name or an IP address is specified in the argument of this constructor, it will be set to this object by calling the SFXInetAddress::Set function internally.
Otherwise, this constructor will do nothing.
[ public ] ~SFXInetAddress(Void);
This destructor cancels to resolve the domain name by calling the SFXInetAddress::Cancel function internally.
[ public, static ] SFXInetAddress AnyInetAddress(Void);
INADDR_ANY (AEE_INADDR_ANY: 0.0.0.0) of the SFXInetAddress type
This function gets INADDR_ANY ( BREW API AEE_INADDR_ANY) of the SFXInetAddress type.
Note | |
---|---|
In BREW, INADDR_ANY ( BREW API AEE_INADDR_ANY) is defined as follows: #define AEE_INADDR_ANY ((INAddr) 0) The BREW API INAddr type is defined as follows: typedef uint32 INAddr; |
SFXInetAddress::LocalInetAddress | SFXInetAddress::LoopbackInetAddress | BREW API AEE_INADDR_ANY | BREW API INAddr
IP address of the BREW API INAddr type
This function gets the IP address of the BREW API INAddr type from this object.
When this object contains a multiple of IP addresses, the IP address can be specified in the index argument. The default index is 0.
The number of IP addresses that this object contains can be obtained by calling the SFXInetAddress::GetCount function.
Note | |
---|---|
When not an IP address but a domain name is set to this object with the SFXInetAddress::SFXInetAddress constructor or the SFXInetAddress::Set function, it is necessary to resolve the domain name with the SFXInetAddress::Resolve function before this function is called. |
Note | |
---|---|
The BREW API INAddr type is defined as follows: typedef uint32 INAddr; |
SFXInetAddress::GetCount | SFXInetAddress::GetIP | SFXInetAddress::Set | SFXInetAddress::SFXInetAddress | SFXInetAddress::Resolve | BREW API INAddr
[ public ] Void Cancel(Void);
This function cancels to resolve the domain name.
Concretely, this function cancels the callback function registered with the SFXInetAddress::Resolve function and releases the SFBNetMgr instance that the SFXInetAddress::Resolve function creates internally.
Tip | |
---|---|
This function is used to cancel to resolve the domain name before the callback function is called after calling the SFXInetAddress::Resolve function. This function is called in the SFXInetAddress::~SFXInetAddress destructor or SFXInetAddress::Clear function. |
SFXInetAddress::Resolve | SFXInetAddress::~SFXInetAddress | SFXInetAddress::Clear | SFBNetMgr
[ public ] Void Clear(Void);
This function cancels the domain name resolution of the SFXInetAddress::Resolve function by calling the SFXInetAddress::Cancel function internally and clears the domain name or IP address setting of this object set with the SFXInetAddress::Set function or the SFXInetAddress::SFXInetAddress constructor.
SFXInetAddress::Set | SFXInetAddress::SFXInetAddress | SFXInetAddress::Cancel | SFXInetAddress::Resolve
[ public, static ] SFXInetAddressConstRef EmptyInstance(Void);
Empty address of the SFXInetAddress type
This function gets an empty address of the SFXInetAddress type.
Tip | |
---|---|
This function is used to return an empty address as the return value of a function. |
[ public, const ] SFXAnsiStringConstRef Get(Void);
Domain name of the SFXAnsiString type
This function gets the domain name of the SFXAnsiString type from this object.
Note | |
---|---|
If an IP address of the BREW API INAddr type is set with the SFXInetAddress::SFXInetAddress constructor or the SFXInetAddress::Set function, it will be returned in the "nnn.nnn.nnn.nnn" (nnn: number) format of the SFXAnsiString type as the domain name. |
SFXInetAddress::Set | SFXInetAddress::SFXInetAddress | SFXInetAddress::operator= | SFXInetAddress::GetIP | SFXAnsiString | BREW API INAddr
[ public, const ] SInt16 GetCount(Void);
Number of IP addresses of this object
This function gets the number of IP addresses set to this object.
Note | |
---|---|
When not an IP address but a domain name is set to this object with the SFXInetAddress::SFXInetAddress constructor or the SFXInetAddress::Set function, it is necessary to resolve the domain name with the SFXInetAddress::Resolve function before this function is called. |
[ public, const ] SFXAnsiString GetIP( SInt16 index = 0 // index );
IP address in the "nnn.nnn.nnn.nnn"(nnn: number) format of the SFXAnsiString type from this object
This function gets the IP address in the "nnn.nnn.nnn.nnn"(nnn: number) format of the SFXAnsiString type from this object.
When this object contains a multiple of IP addresses, the IP address can be specified in the index argument. The default index is 0.
The number of IP addresses that this object contains can be obtained by calling the SFXInetAddress::GetCount function.
Note | |
---|---|
When not an IP address but a domain name is set to this object with the SFXInetAddress::SFXInetAddress constructor or the SFXInetAddress::Set function, it is necessary to resolve the domain name with the SFXInetAddress::Resolve function before this function is called. |
SFXInetAddress::GetCount | SFXInetAddress::AsINAddr | SFXInetAddress::SFXInetAddress | SFXInetAddress::Set | SFXInetAddress::Resolve | SFXAnsiString
[ public, static ] SFXInetAddress LocalInetAddress(Void);
IP address of the local host or device of the SFXInetAddress type
This function gets the IP address of the local host or device of the SFXInetAddress type.
Note | |
---|---|
This function internally calls the SFBNetMgr::GetMyIPAddr function. |
SFXInetAddress::AnyInetAddress | SFXInetAddress::LoopbackInetAddress | SFBNetMgr::GetMyIPAddr | BREW API INETMGR_GetMyIPAddr
[ public, static ] SFXInetAddress LoopbackInetAddress(Void);
Loopback address (AEE_BREW_LOOPBACK: 127.0.0.69) of the SFXInetAddress type
This function gets the loopback address of BREW API AEE_BREW_LOOPBACK that is converted into the SFXInetAddress type.
Note | |
---|---|
BREW API AEE_BREW_LOOPBACK is defined as follows: #define AEE_BREW_LOOPBACK (0x7f000045L) |
Tip | |
---|---|
This function is valid in BREW 2.1 or above. |
SFXInetAddress::AnyInetAddress | SFXInetAddress::LocalInetAddress | BREW API AEE_BREW_LOOPBACK
[ public ] SFCError Resolve( CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
This function resolves the domain name included in the address set with the SFXInetAddress::SFXInetAddress constructor or the SFXInetAddress::Set function.
The resolved IP addresses can be obtained with the SFXInetAddress::GetIP / SFXInetAddress::AsINAddr function.
As a result of domain name resolution, a domain name may be converted into a multiple of IP addresses. In such a case, by specifying the index value in the argument of the SFXInetAddress::GetIP / SFXInetAddress::AsINAddr function, any IP address can be obtained. The total number of IP addresses can be obtained with the SFXInetAddress::GetCount function.
When the domain name resolution completes, the callback function specified in the argument will be called. However, if an error occurs in this function, it will not be called.
The domain name resolution can be canceled by calling the SFXInetAddress::Cancel function before the callback function is called.
First argument of the callback function | |
---|---|
This function internally calls the BREW API INETMGR_GetHostByName function. The following return value(error) of the BREW API INETMGR_GetHostByName function will be passed to the first argument of the callback function:
|
Note | |
---|---|
If an IP address is set or a domain name is set in the "nnn.nnn.nnn.nnn"(nnn: number) format, there is no need to resolve the domain name by calling the SFXInetAddress::Resolve function. When socket communication is performed using SophiaFramework UNIVERSE, there is no need to resolve the domain name by calling the SFXInetAddress::Resolve function since the domain name will be automatically resolved only by passing the address(domain name and port number) of the SFXSocketAddress type. |
class MyClass { SFXInetAddress _address; Void Function(Void); XALLBACK_DECLARE_SFXINETADDRESS(ResolveCallback) }; Void MyClass::Function(Void) { SFCError error; // set domain name if ((error = _address.Set("http://www.example.com/test"); == SFERR_NO_ERROR) { // resolve domain name(result of domain name resolution will be notified to the ResolveCallback function) error = _address.Resolve(XALLBACK_INTERNAL(ResolveCallback)); } if (error != SFERR_NO_ERROR) { // if an error occurs, the ResolveCallback function will not be called // error handling ... } } // callback function notified of result of domain name resolution XALLBACK_IMPLEMENT_SFXINETADDRESS(MyClass, ResolveCallback, error) { SInt16 i; // display domain name on BREW Output window TRACE("%s",_address.Get().GetCString()); // repeat number of IP addresses for(i = 0 ; i < _address.GetCount() ; i++){ // display IP address on BREW Output window TRACE("%s",_address.GetIP(i).GetCString()); } }
SFXInetAddress::Set | SFXInetAddress::SFXInetAddress | SFXInetAddress::operator= | SFXInetAddress::GetIP | SFXInetAddress::AsINAddr | SFXInetAddress::Cancel | SFXInetAddress::CallbackSPP | SFBNetMgr | BREW API INETMGR_GetHostByName
[ public ] SFCError Set( SFXInetAddressConstRef param // source SFXInetAddress );
[ public ] SFCError Set( SFXAnsiStringConstRef param // domain name );
[ public ] SFCError Set( INAddr inaddr // IP Address );
This function sets the specified domain name or IP address to this object.
The IP address or domain name set to this object with this function can be obtained by calling the SFXInetAddress::Get function.
If the argument is of the SFXAnsiString type, a string in the following format can be specified. And only the <domain name> will be extracted from this string and set to this object.
<protocol> :// <domain name> : <port> / <path>
or
<account> @ <domain>
When <domain name> is in the "nnn.nnn.nnn.nnn" (nnn: number) format or the argument is an IP address of the BREW API INAddr type, there is no need to call the SFXInetAddress::Resolve function in order to get the IP address. In this case, the IP address can be obtained by calling the SFXInetAddress::AsINAddr / SFXInetAddress::GetIP function without any domain name resolution.
Caution | |
---|---|
This function internally calls the SFXInetAddress::Cancel function first. Therefore, if this function is called during the domain name resolution( from calling the SFXInetAddress::Resolve function until the result is notified to the callback function), the domain name resolution will be canceled. |
SFXInetAddress address;
SFXAnsiString domain;
address.Set("http://www.example.com:80/test");
domain = address.Get(); // domain: "www.example.com"
SFXInetAddress address; INAddr ipaddress_INAddr; SFXAnsiString ipaddress_SFXAnsiString; address.Set("127.0.0.1/test"); ipaddress_INAddr = address.AsINAddr(); // get IP address("127.0.0.1") of the INAddr type ipaddress_SFXAnsiString = address.GetIP(); // get IP address("127.0.0.1") of the SFXAnsiString type
SFXInetAddress::Get | SFXInetAddress::operator= | SFXInetAddress::Clear | SFXInetAddress::Cancel | SFXInetAddress::SFXInetAddress | SFXInetAddress::GetIP | SFXInetAddress::AsINAddr | SFXInetAddress::Resolve | SFXAnsiString | BREW API INAddr
[ public ] SFXInetAddressRef operator=( SFXInetAddressConstRef param // source SFXInetAddress );
This operator assigns the specified address of the SFXInetAddress type.
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 - 2024 Sophia Cradle Incorporated All Rights Reserved. |