SophiaFramework UNIVERSE 5.3 |
#include <SFXSocketAddress.h.hpp>
class SFXSocketAddress : public SFXInetAddress;
SFMTYPEDEFCLASS(SFXSocketAddress)
The SFXSocketAddress class inheriting from SFXInetAddress provides the function to manage domain and/or IP address, port number.
In the SFXTCPSocket / SFXSSLSocket / SFXUDPSocket classes, domain name resolution will be automatically performed only by passing the address of the SFXSocketAddress type.
How to use the SFXSocketAddress clas
Note | |
---|---|
There is no need to resolve domain with the SFXInetAddress::Resolve function when an IP address is specified with the SFXSocketAddress::SFXSocketAddress constructor or the SFXSocketAddress::Set function. |
Example 843. Method to resolve a domain
class MyClass { SFXSocketAddress _socket; Void Function(Void); XALLBACK_DECLARE_SFXINETADDRESS(ResolveCallback) }; Void MyClass::Function(Void) { SFCError error; // set domain and port number if ((error = _address.Set("http://www.example.com/test:80"); == SFERR_NO_ERROR) { // resolve domain(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_SFXSOCKETADDRESS(MyClass, ResolveCallback, error) { SInt16 i; // display domain and port number on BREW Output window TRACE("%s",_socket.Get().GetCString()); // domain and port number TRACE("%s",_socket.GetHost().GetCString()); // domain TRACE("%s",_socket.GetPort().GetCString()); // port number // repeat number of IP addresses for(i = 0 ; i < _socket.GetCount() ; i++){ // display IP address on BREW Output window TRACE("%s",_socket.GetIP(i).GetCString()); } }
Constructor/Destructor |
---|
SFXSocketAddress( Void ) Constructor of the SFXSocketAddress class.
|
SFXSocketAddress(
SFXSocketAddressConstRef param
) Constructor of the SFXSocketAddress class.
|
SFXSocketAddress(
SFXAnsiStringConstRef param
) Constructor of the SFXSocketAddress class.
|
SFXSocketAddress(
SFXInetAddressConstRef host
, UInt16 port
) Constructor of the SFXSocketAddress class.
|
SFXSocketAddress(
SFXAnsiStringConstRef host
, UInt16 port
) Constructor of the SFXSocketAddress class.
|
SFXSocketAddress(
INAddr inaddr
, INPort inport
) Constructor of the SFXSocketAddress class.
|
Public Functions | |
---|---|
INPort |
AsINPort( Void ) Get the port number of the INPort type from this object.
|
Void |
Clear( Void ) Clear the domain name or IP address and port number setting of this object.
|
static SFXSocketAddressConstRef |
EmptyInstance( Void ) Get an empty address.
|
SFXAnsiString |
Get( Void ) Get the domain name and port number of the SFXAnsiString type from this object.
|
SFXAnsiStringConstRef |
GetHost( Void ) Get the domain name of the SFXAnsiString type from this object.
|
UInt16 |
GetPort( Void ) Get the port number of the UInt16 type from this object.
|
SFCError |
Set(
SFXSocketAddressConstRef param
) Set the specified domain name or IP address and port number to this object.
|
SFCError |
Set(
SFXAnsiStringConstRef param
) Set the specified domain name or IP address and port number to this object.
|
SFCError |
Set(
SFXInetAddressConstRef host
, UInt16 port
) Set the specified domain name or IP address and port number to this object.
|
SFCError |
Set(
SFXAnsiStringConstRef host
, UInt16 port
) Set the specified domain name or IP address and port number to this object.
|
SFCError |
Set(
INAddr inaddr
, INPort inport
) Set the specified domain name or IP address and port number to this object.
|
SFCError |
SetHost(
SFXInetAddressConstRef param
) Set the domain name of this object to the specified value.
|
SFCError |
SetHost(
SFXAnsiStringConstRef param
) Set the domain name of this object to the specified value.
|
Void |
SetPort(
UInt16 param
) Set the port number of this object to the specified value.
|
SFXSocketAddressRef |
operator=(
SFXSocketAddressConstRef param
) Assign the specified address of the SFXSocketAddress type.
|
static SFXInetAddress |
AnyInetAddress( Void )
(inherits from SFXInetAddress)
Get INADDR_ANY of the SFXInetAddress type.
|
INAddr |
AsINAddr(
SInt16 index = 0
)
(inherits from SFXInetAddress)
Get the IP address of the INAddr type from this object.
|
Void |
Cancel( Void )
(inherits from SFXInetAddress)
Cancel to resolve the domain name.
|
SInt16 |
GetCount( Void )
(inherits from SFXInetAddress)
Get the number of IP addresses from this object.
|
SFXAnsiString |
GetIP(
SInt16 index = 0
)
(inherits from SFXInetAddress)
Get the IP address of the SFXAnsiString type from this object.
|
static SFXInetAddress |
LocalInetAddress( Void )
(inherits from SFXInetAddress)
Get the IP address of the local host or device.
|
static SFXInetAddress |
LoopbackInetAddress( Void )
(inherits from SFXInetAddress)
Get the loopback address of the SFXInetAddress type.
|
SFCError |
Resolve(
CallbackSPP spp
, VoidPtr reference
)
(inherits from SFXInetAddress)
Resolve the domain name.
|
Types |
---|
CallbackSPP
(inherits from SFXInetAddress)
Type that represents the callback function.
|
[ public, explicit ] SFXSocketAddress(Void);
[ public ] SFXSocketAddress( SFXSocketAddressConstRef param // source SFXSocketAddress );
[ public, explicit ] SFXSocketAddress( SFXAnsiStringConstRef param // domain and port number character string );
[ public, explicit ] SFXSocketAddress( SFXInetAddressConstRef host // source SFXInetAddress UInt16 port // port number );
[ public, explicit ] SFXSocketAddress( SFXAnsiStringConstRef host // domain character string UInt16 port // port number );
[ public, explicit ] SFXSocketAddress( INAddr inaddr // IP address INPort inport // port number );
If a domain name or an IP address and a port number are specified in the arguments of this constructor, they will be set to this object by calling the SFXSocketAddress::Set function internally.
Otherwise, this constructor will do nothing.
[ public, const ] INPort AsINPort(Void);
Port number of the BREW API INPort type
This function gets the port number of the BREW API INPort type from this object.
Note | |
---|---|
The BREW API INPort type defined as follows: typedef uint16 INPort; |
SFXSocketAddress::GetPort | SFXSocketAddress::Set | SFXSocketAddress::SetPort | SFXSocketAddress::SFXSocketAddress | BREW API INPort
[ 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 and port number setting of this object set with the SFXSocketAddress::Set / SFXSocketAddress::SetHost / SFXSocketAddress::SetPort function or the SFXSocketAddress::SFXSocketAddress constructor.
SFXSocketAddress::Set | SFXSocketAddress::SetHost | SFXSocketAddress::SetPort | SFXSocketAddress::SFXSocketAddress | SFXInetAddress::Cancel | SFXInetAddress::Resolve
[ public, static ] SFXSocketAddressConstRef EmptyInstance(Void);
Empty address of the SFXSocketAddress type
This function gets an empty address of the SFXSocketAddress type.
Tip | |
---|---|
This function is used to return an empty address as the return value of a function. |
[ public, const ] SFXAnsiString Get(Void);
["Domain name" + ":" + "Port number"] string of the SFXAnsiString type
This function gets the domain name and port number ["Domain name" + ":" + "Port number"] of the SFXAnsiString type from this object.
Note | |
---|---|
If an IP address of the BREW API INAddr type is set with the SFXSocketAddress::SFXSocketAddress constructor or the SFXSocketAddress::Set function, it will be returned in the "nnn.nnn.nnn.nnn" (nnn: number) format of the SFXAnsiString type as the domain name. |
SFXSocketAddress::Set | SFXSocketAddress::SetHost | SFXSocketAddress::SFXSocketAddress | SFXSocketAddress::operator= | SFXSocketAddress::GetHost | SFXSocketAddress::GetPort | SFXInetAddress::GetIP | SFXAnsiString | BREW API INAddr
[ public, const ] SFXAnsiStringConstRef GetHost(Void);
Domain name of the SFXAnsiString type
This function gets the domain name of the SFXAnsiString type from this object.
This function is same as the SFXInetAddress::Get function.
SFXSocketAddress::SetHost SFXSocketAddress::Set | SFXSocketAddress::SFXSocketAddress | SFXSocketAddress::Get | SFXSocketAddress::GetPort | SFXInetAddress::Get | SFXInetAddress::GetIP | SFXAnsiString
[ public, const ] UInt16 GetPort(Void);
Port number of the UInt16 type
This function gets the port number of the UInt16 type from this object.
SFXSocketAddress::SetPort | SFXSocketAddress::AsINPort | SFXSocketAddress::Get | SFXSocketAddress::GetHost | SFXInetAddress::GetIP | SFXSocketAddress::Set | SFXSocketAddress::SFXSocketAddress
[ public ] SFCError Set( SFXSocketAddressConstRef param // source SFXSocketAddress );
[ public ] SFCError Set( SFXAnsiStringConstRef param // domain and port number string );
[ public ] SFCError Set( SFXInetAddressConstRef host // source SFXInetAddress UInt16 port // port number );
[ public ] SFCError Set( SFXAnsiStringConstRef host // domain string UInt16 port // port number );
[ public ] SFCError Set( INAddr inaddr // IP address INPort inport // port number );
This function sets the specified domain name or IP address and port number to this object.
The IP address or domain name and port number set to this object with this function can be obtained by calling the SFXSocketAddress::Get function. And the domain name or the port number can be obtained by calling the SFXSocketAddress::GetHost function or the SFXSocketAddress::GetPort function respectively.
If the argument is of the SFXAnsiString type, a string in the following format can be specified. And <domain name> and <port numeber> (default: 0) will be extracted from this string and set to this object.
<protocol> :// <domain name> : <port numeber> / <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. |
SFXSocketAddress address; SFXAnsiString domain, host, port; address.Set("http://www.example.com:80/test"); domain = address.Get(); // get domain name and port number: "www.example.com:80" host = address.GetHost(); // get domain name : "www.example.com" port = address.GetPort(); // get port number: "80"
SFXSocketAddress address; INAddr ipaddress_INAddr; INPort port_INPort; SFXAnsiString ipaddress_SFXAnsiString; address.Set("127.0.0.1/test", 80); ipaddress_INAddr = address.AsINAddr(); // get IP address("127.0.0.1") of INAddr type inport_INPort = address.AsINPort(); // get port number("80") of INPort type ipaddress_SFXAnsiString = address.GetIP(); // get IP address("127.0.0.1") of SFXAnsiString type
SFXSocketAddress::Get | SFXSocketAddress::GetHost | SFXSocketAddress::GetPort | SFXSocketAddress::AsINPort | SFXSocketAddress::SetHost | SFXSocketAddress::SetPort | SFXSocketAddress::operator= | SFXSocketAddress::Clear | SFXInetAddress::Cancel | SFXInetAddress::SFXInetAddress | SFXInetAddress::GetIP | SFXInetAddress::AsINAddr | SFXInetAddress::Resolve | SFXAnsiString | BREW API INAddr
[ public ] SFCError SetHost( SFXInetAddressConstRef param // source SFXInetAddress );
[ public ] SFCError SetHost( SFXAnsiStringConstRef param // domain name );
This function sets the domain name of this object to the specified value by calling the SFXInetAddress::Set function internally.
Tip | |
---|---|
This function is same as the SFXInetAddress::Set function. |
Note | |
---|---|
The domain name can be set with the SFXSocketAddress::Set function or the SFXSocketAddress::SFXSocketAddress constructor. |
SFXSocketAddress::GetHost | SFXSocketAddress::Set | SFXSocketAddress::SFXSocketAddress | SFXInetAddress::Set
This function sets the port number of this object to the specified value.
Default: 0
Note | |
---|---|
The port number can be set with the SFXSocketAddress::Set function or the SFXSocketAddress::SFXSocketAddress constructor. |
SFXSocketAddress::GetPort | SFXSocketAddress::Set | SFXSocketAddress::SFXSocketAddress | SFXSocketAddress::SetHost
[ public ] SFXSocketAddressRef operator=( SFXSocketAddressConstRef param // source SFXSocketAddress );
This operator assigns the specified address of the SFXSocketAddress type.
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |