PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFXSocketAddress
Class for managing a domain name and/or an IP address 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 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

  1. Set domain with the SFXSocketAddress::SFXSocketAddress constructor or the SFXSocketAddress::Set function
  2. Resolve the domain with the SFXInetAddress::Resolve function. The callback function notified of result of domain name resolution should specified in the argument of this function.
  3. Domain resolution can be canceled by calling the SFXInetAddress::Cancel function.
  4. After domain name resolution finishes, the callback function registered in Step 2. will be called.
  5. In the callback function, processing after domain name resolution is described.
[Note] 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());  
     }
    
}

Reference

SFXTCPSocket | SFXSSLSocket | SFXUDPSocket | 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 )
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.

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

Reference

SFXSocketAddress::Set


SFXSocketAddress::AsINPort
Get the port number of the INPort type from this object.
[ public, const ]
INPort AsINPort(Void);

Return value

Port number of the BREW API INPort type

Description

This function gets the port number of the BREW API INPort type from this object.

[Note] Note

The BREW API INPort type defined as follows:

typedef uint16 INPort;

Reference

SFXSocketAddress::GetPort | SFXSocketAddress::Set | SFXSocketAddress::SetPort | SFXSocketAddress::SFXSocketAddress | BREW API INPort


SFXSocketAddress::Clear
Clear the domain name or IP address and port number setting of this object.
[ public ]
Void Clear(Void);

Description

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.

Reference

SFXSocketAddress::Set | SFXSocketAddress::SetHost | SFXSocketAddress::SetPort | SFXSocketAddress::SFXSocketAddress | SFXInetAddress::Cancel | SFXInetAddress::Resolve


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

Return value

Empty address of the SFXSocketAddress type

Description

This function gets an empty address of the SFXSocketAddress type.

[Tip] Tip
This function is used to return an empty address as the return value of a function.

SFXSocketAddress::Get
Get the domain name and port number of the SFXAnsiString type from this object.
[ public, const ]
SFXAnsiString Get(Void);

Return value

["Domain name" + ":" + "Port number"] string of the SFXAnsiString type

Description

This function gets the domain name and port number ["Domain name" + ":" + "Port number"] of the SFXAnsiString type from this object.

[Note] 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.

Reference

SFXSocketAddress::Set | SFXSocketAddress::SetHost | SFXSocketAddress::SFXSocketAddress | SFXSocketAddress::operator= | SFXSocketAddress::GetHost | SFXSocketAddress::GetPort | SFXInetAddress::GetIP | SFXAnsiString | BREW API INAddr


SFXSocketAddress::GetHost
Get the domain name of the SFXAnsiString type from this object.
[ public, const ]
SFXAnsiStringConstRef GetHost(Void);

Return value

Domain name of the SFXAnsiString type

Description

This function gets the domain name of the SFXAnsiString type from this object.

This function is same as the SFXInetAddress::Get function.

Reference

SFXSocketAddress::SetHost SFXSocketAddress::Set | SFXSocketAddress::SFXSocketAddress | SFXSocketAddress::Get | SFXSocketAddress::GetPort | SFXInetAddress::Get | SFXInetAddress::GetIP | SFXAnsiString


SFXSocketAddress::GetPort
Get the port number of the UInt16 type from this object.
[ public, const ]
UInt16 GetPort(Void);

Return value

Port number of the UInt16 type

Description

This function gets the port number of the UInt16 type from this object.

Reference

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


SFXSocketAddress::Set
Set the specified domain name or IP address and port number to this object.
[ 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 insufficient memory: SFERR_NO_MEMORY

Description

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] 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.

Example

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

Reference

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


SFXSocketAddress::SetHost
Set the domain name of this object to the specified value.
[ 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

This function sets the domain name of this object to the specified value by calling the SFXInetAddress::Set function internally.

[Tip] Tip

This function is same as the SFXInetAddress::Set function.

[Note] Note

The domain name can be set with the SFXSocketAddress::Set function or the SFXSocketAddress::SFXSocketAddress constructor.

Reference

SFXSocketAddress::GetHost | SFXSocketAddress::Set | SFXSocketAddress::SFXSocketAddress | SFXInetAddress::Set


SFXSocketAddress::SetPort
Set the port number of this object to the specified value.
[ public ]
Void SetPort(
    UInt16 param   // port number
);

Description

This function sets the port number of this object to the specified value.

Default: 0

[Note] Note

The port number can be set with the SFXSocketAddress::Set function or the SFXSocketAddress::SFXSocketAddress constructor.

Reference

SFXSocketAddress::GetPort | SFXSocketAddress::Set | SFXSocketAddress::SFXSocketAddress | SFXSocketAddress::SetHost


SFXSocketAddress::operator=
Assign the specified address of the SFXSocketAddress type.
[ public ]
SFXSocketAddressRef operator=(
    SFXSocketAddressConstRef param   // source SFXSocketAddress
);

Description

This operator assigns the specified address of the SFXSocketAddress type.

Reference

SFXSocketAddress::Set