PrevNextUpHome SophiaFramework UNIVERSE 5.1
SFXSocketAddress
Class for managing an IP address, a domain, and a port number
#include <SFXSocketAddress.h.hpp>
class SFXSocketAddress : public SFXInetAddress;
SFMTYPEDEFCLASS(SFXSocketAddress)

Inheritance diagram

 Inheritance diagram of SFXSocketAddressClass

Collaboration diagram

 Collaboration diagram of SFXSocketAddressClass

Description

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

  1. Set a domain in the constructor or SFXSocketAddress::Set function
  2. Resolve the domain using the SFXInetAddress::Resolve function, and register a callback function as an argument of this function.
  3. The registered callback function will be called after notified of the address resolution.

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
     }
    
}

Reference

SFXTCPSocket | SFXInetAddress

Member

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.

SFXSocketAddress::SFXSocketAddress
Constructor of the SFXSocketAddress class.
[ 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
);

Description

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" ).

Reference

SFXSocketAddress::Set | SFXSocketAddress::operator=


SFXSocketAddress::AsINPort
Convert the port number into the INPort format.
[ public, const ]
INPort AsINPort(Void);

Return value

Return the port number in the INPort format.

Reference

SFXSocketAddress::GetPort


SFXSocketAddress::Clear
Make IP address and port number empty.
[ public ]
Void Clear(Void);

Reference

SFXSocketAddress::Set


SFXSocketAddress::EmptyInstance
Get an empty address.
[ public, static ]
SFXSocketAddressConstRef EmptyInstance(Void);

Return value

Return an empty string of the SFXSocketAddress class.


SFXSocketAddress::Get
Get domain and port number of string.
[ public, const ]
SFXAnsiString Get(Void);

Return value

Return [ domain name + ":" + port number ] string.

Reference

SFXSocketAddress::GetHost | SFXSocketAddress::GetPort | SFXInetAddress::GetIP


SFXSocketAddress::GetHost
Get the domain.
[ public, const ]
SFXAnsiStringConstRef GetHost(Void);

Reference

SFXSocketAddress::Get | SFXSocketAddress::GetPort SFXInetAddress::GetIP


SFXSocketAddress::GetPort
Get the port number.
[ public, const ]
UInt16 GetPort(Void);

Reference

SFXSocketAddress::AsINPort | SFXSocketAddress::Get | SFXSocketAddress::GetHost | SFXInetAddress::GetIP


SFXSocketAddress::Set
Set the domain, IP address, and port number.
[ 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
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If the IP address is not found: SFERR_INVALID_PARAM
  • If the IP address or port number cannot be converted: SFERR_FAILED
  • If insufficient memory: SFERR_NO_MEMORY

Description

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.

Example

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 

Reference

SFXSocketAddress::operator= | SFXInetAddress::AsINAddr | SFXInetAddress::Resolve


SFXSocketAddress::SetHost
Set the domain name.
[ public ]
SFCError SetHost(
    SFXInetAddressConstRef param   // source SFXInetAddress
);
[ public ]
SFCError SetHost(
    SFXAnsiStringConstRef param   // domain name
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Description

Similar to the SFXInetAddress::Set function.

Reference

SFXInetAddress::Set


SFXSocketAddress::SetPort
Set the port number.
[ public ]
Void SetPort(
    UInt16 param   // port number
);

Reference

SFXSocketAddress::Set | SFXSocketAddress::SetHost


SFXSocketAddress::operator=
Assign a domain, IP address, and port number.
[ public ]
SFXSocketAddressRef operator=(
    SFXSocketAddressConstRef param   // source SFXSocketAddress
);

Description

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.

Reference

SFXSocketAddress::Set