![]() ![]() ![]()
|
SophiaFramework UNIVERSE 5.1 |
#include <SFXSocketAddress.h.hpp>
class SFXSocketAddress : public SFXInetAddress;
SFMTYPEDEFCLASS(SFXSocketAddress)


The SFXSocketAddress class inherits from the SFXInetAddress class for managing an IP address and a domain.
The SFXTCPSocket class resolves the address by setting a domain using the SFXSocketAddress class, and passing it to the SFXTCPSocket::Connect function.
How to use the SFXSocketAddress clas
Example 836. 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 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_SFXSOCKETADDRESS(MyClass, ResolveCallback, error)
{
SInt16 i;
// get result
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++){
// get result
TRACE("%s",_socket.GetIP(i).GetCString()); // IP address
}
}
| 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 ) Convert the port number into the INPort format.
|
| Void |
Clear( Void ) Make IP address and port number empty.
|
| static SFXSocketAddressConstRef |
EmptyInstance( Void ) Get an empty address.
|
| SFXAnsiString |
Get( Void ) Get domain and port number of string.
|
| SFXAnsiStringConstRef |
GetHost( Void ) Get the domain.
|
| UInt16 |
GetPort( Void ) Get the port number.
|
| SFCError |
Set(
SFXSocketAddressConstRef param
) Set the domain, IP address, and port number.
|
| SFCError |
Set(
SFXAnsiStringConstRef param
) Set the domain, IP address, and port number.
|
| SFCError |
Set(
SFXInetAddressConstRef host
, UInt16 port
) Set the domain, IP address, and port number.
|
| SFCError |
Set(
SFXAnsiStringConstRef host
, UInt16 port
) Set the domain, IP address, and port number.
|
| SFCError |
Set(
INAddr inaddr
, INPort inport
) Set the domain, IP address, and port number.
|
| SFCError |
SetHost(
SFXInetAddressConstRef param
) Set the domain name.
|
| SFCError |
SetHost(
SFXAnsiStringConstRef param
) Set the domain name.
|
| Void |
SetPort(
UInt16 param
) Set the port number.
|
| SFXSocketAddressRef |
operator=(
SFXSocketAddressConstRef param
) Assign a domain, IP address, and port number.
|
| static SFXInetAddress |
AnyInetAddress( Void )
(inherits from SFXInetAddress)
Convert into the Any Address of the SFXInetAddress class.
|
| INAddr |
AsINAddr(
SInt16 index = 0
)
(inherits from SFXInetAddress)
Convert the IP address into the INAddr format.
|
| Void |
Cancel( Void )
(inherits from SFXInetAddress)
Cancel the resolution of IP address.
|
| SInt16 |
GetCount( Void )
(inherits from SFXInetAddress)
Get the number of IP addresses.
|
| SFXAnsiString |
GetIP(
SInt16 index = 0
)
(inherits from SFXInetAddress)
Get the IP address.
|
| static SFXInetAddress |
LocalInetAddress( Void )
(inherits from SFXInetAddress)
Return the local IP address.
|
| static SFXInetAddress |
LoopbackInetAddress( Void )
(inherits from SFXInetAddress)
Return the Loopback Address.
|
| SFCError |
Resolve(
CallbackSPP spp
, VoidPtr reference
)
(inherits from SFXInetAddress)
Resolve 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 the argument is of the SFXAnsiString::Set function, the domain string takes the following format:
<protocol> :// <account> @ <domain> : <port> / <path>
The <domain> part and <port> part are taken out and set as domain and port number respectively (the port number specified by the argument has higher priority) 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, const ] INPort AsINPort(Void);
Return the port number in the INPort format.
[ public ] Void Clear(Void);
[ public, static ] SFXSocketAddressConstRef EmptyInstance(Void);
Return an empty string of the SFXSocketAddress class.
[ public, const ] SFXAnsiString Get(Void);
Return [ domain name + ":" + port number ] string.
[ public, const ] SFXAnsiStringConstRef GetHost(Void);
[ public, const ] UInt16 GetPort(Void);
SFXSocketAddress::AsINPort | SFXSocketAddress::Get | SFXSocketAddress::GetHost | SFXInetAddress::GetIP
[ 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 );
The domain string takes the following format:
<protocol> :// <account> @ <domain> : <port> / <path>
The <domain> part and <port> part are taken out and set as domain and port number respectively (the port number specified by the argument has higher priority) 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 SFXSocketAddress::Set function is called while resolving.
SFXSocketAddress address;
address.Set("http://www.example.com:80/test");
address.GetHost(); // return "www.example.com"
address.GetPort(); // return 80
address.Get(); // return "www.example.com:80"
SFXSocketAddress address;
address.Set("127.0.0.1/test", 80);
address.AsINAddr(); // return 127.0.0.1 in INAddr format
address.AsINPort(); // return 80 in INPort format
[ public ] SFCError SetHost( SFXInetAddressConstRef param // source SFXInetAddress );
[ public ] SFCError SetHost( SFXAnsiStringConstRef param // domain name );
Similar to the SFXInetAddress::Set function.
[ public ] SFXSocketAddressRef operator=( SFXSocketAddressConstRef param // source SFXSocketAddress );
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>
The <domain> part and <port> part are taken out and set as domain and port number respectively (the port number specified by the argument has higher priority) 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 SFXSocketAddress::operator= function is called while resolving.
|
Copyright(c) 2002 - 2010 Sophia Cradle Incorporated All Rights Reserved. |
![]() ![]() ![]()
|