![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |
There are two types of classes for managing a network address(an IP address, a domain, and a port number).
Table 16.1. Network Address Management Classes
| Class Name | Description |
|---|---|
| SFXInetAddress | Class for managing an IP address and a domain. |
| SFXSocketAddress | Class for managing an IP address, a domain, and a port number |
To resolve the domain manually, use the SFXInetAddress::Resolve function.
![]() |
About MIF File Setting |
|---|---|
Never forget to turn on the Network option in the MIF file setting of privilege level. | |
Example 16.1. Define the IP address, domain, and port number
SFXSocketAddress address1("127.0.0.1"); // IP address (port number: 0)
SFXSocketAddress address2("127.0.0.1:80"); // IP address and port number
SFXSocketAddress address3("www.example.com:80"); // Domain and port number
Example 16.2. Set the address
SFXSocketAddress address;
address.Set("www.example.com:80");
address.Set("http://www.example.com:80/dir1/dir2/index.html");
address.Set("http://user@127.0.0.1:80/dir1/");
The string can be set in various formats to the argument of SFXSocketAddress::Set funtion or the constructor, but strings other than domain and port number are ignored.
Example 16.3. Set the address: in case of TCP Communication
// erro handling is omitted for simplified explanation SFXSocketAddress address("www.example.com:80"); SFXTCPSocket _socket; // initial processing _socket.Open(); // address is automatically resolved by passing domain argument of SFXSocketAddress type // connection establishment will be notified to OnConnect function _socket.Connect(address, CALLBACK_FUNCTION(OnConnect));
If SFXTCPSocket class is used in TCP communication, the address is automatically resolved if domain name is set by SFXSocketAddress.
Example 16.4. The method to resolve the domain
// SFXSocketAddress instance is defined as class member variable for the callback function class MyClass { private: SFXSocketAddress _address; public: Void Start(Void); CALLBACK_DECLARE_SFXSOCKETADDRESS(ResolveCallback); }; Void MyClass::Start(Void) { SFCError error; // set domain and port number if ((error = _address.Set("www.example.com:80")) == SFERR_NO_ERROR) { // resolve domain ( completion of resolving domain will be notified to ResolveCallback function ) error = _address.Resolve(CALLBACK_FUNCTION(ResolveCallback)); } if (error != SFERR_NO_ERROR) { // error handling (callback function will not be called) ... } } // callback funtion notified of completion of resolving domain CALLBACK_IMPLEMENT_SFXSOCKETADDRESS(MyClass, ResolveCallback, error) { SFXAnsiString ip; SInt32 i; for (i = 0; i < _address.GetCount(); ++i) { ip = _address.GetIP(i); // get result TRACE("%s",ip.GetCString()); // display result } }
Since the domain may be converted into multiple IP addresses after resolving, get the specific IP address by using its index number.
![]() |
SFXSocketAddress Instance |
|---|---|
If the SFXSocketAddress instance is released before the callback function is called, program will not work correctly. | |
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|