Ace Installation Guide and example

Source: Internet
Author: User
Tags install openssl openssl library
The Adaptive Communication Environment (ACE) is a free and open-source object-oriented framework that implements many core design modes for large-scale concurrent communication software. ACE provides a rich set of reusable C ++ encapsulation classes and framework components, and can implement most common communication software functions across platforms. This article describes how to install and configure ace through a few simple and rough examples. Through these simple small examples, we can lead you to enter the ace world as quickly as possible. Our first step is to seek perfection, but to get started.

First, I want to introduce the environment used in this article. All the details mentioned in this Article will be matched with this environment. If you encounter problems during configuration installation, you can also use QQ (21807822) or blog (http://dukejoe.yeah.net) to contact me. I am using AIX 5.3 Windows XP Home ace 5.5 Visual Studio. NET 2003. If the environment does not fully match, the installation process may be slightly different.

The download ace page isObtaining ace, Tao, And ciaoSome friends may not be familiar with English, so you can directly click the link below to downloadACE-5.5.zip(Windows)ACE-5.5.tar.gz(UNIX platform ). If the link is too long and the link may be too long, you 'd better learn some simple English and download the current version directly from the ace download page. The latest release of ACE in this article is 5.5.

Take windows as an example. Use winzipzipto decompress ace-5.5.zip. It is best to keep the hard disk space above 2 GB. I keep 8 GB (after all, what else should I do). The decompressed directory is similar

D:/ace <directory>
-- Ace_wrappers <directory>
-- Ace <directory>
-- Include <directory>
-- Lib <directory>

Go to the D:/ACE/ace_wrappers/ace directory and create a config. h file. Add a sentence # include "config-win32.h" and now use Visual Studio. NET 2003 open the ace under D:/ACE/ace_wrappers. SLN, after opening the solution, you can choose to regenerate the solution just like you do other development, and then we don't have to perform any operations. After a long wait, we will generate the Lib, DLL and other files required by ace in the lib directory. So far, the process of building ace on Windows has basically ended.

In step 2, add the D:/ACE/ace_wrappers/lib directory to the path, so that the program developed by Ace can run.

Next, we need to configure VC. Open Visual Studio. NET 2003 tool --> Option --> project --> VC ++ directory, add D:/ACE/ace_wrappers to "include directory", and add D in "library file: /ACE/ace_wrappers/lib: Add D:/ACE/ace_wrappers/ace to the source file. In this way, the VC configuration is completed. When the header file is used in the program, it will be searched in the D:/ACE/ace_wrappers/ace directory, and the generated DLL and Lib file, such as aced. lib, which can be found in D:/ACE/ace_wrappers/lib ). The following example shows that both the server and client have passed the test on AIX and windows and can run on both systems. First, start the server and enable listening. After the client connects, it sends a message at will. The server also sends the host time of the server to the client. These two applets are very simple and there are still many shortcomings. However, we hope that readers will have a perceptual knowledge of Ace's preliminary use, you can also learn ace based on some classes mentioned in the source code. Note: If the program is used in Windows, you need to add the aced. Lib Library to the "link" in the project property to link to the ace library. If it is used on AIX, you can generate a setenv. Sh, and then add

Ace_root =/Rpt/gaohw/ace_wrappers; export ace_root
LD_LIBRARY_PATH = $ LD_LIBRARY_PATH: $ {ace_root}/build/ACE/. libs/; export LD_LIBRARY_PATH

Ace_root directory, you should modify according to your own system. The makefile used in Aix is as follows:

ALL: test1

Test1: test1.o
Xlc_r-O test1 test1.o-L $ {ace_root}/build/ACE/. libs/-Example

Test1.o: test1.cpp
Xlc_r-c-o test1.o-I $ {ace_root} test1.cpp

Clean:
Rm-F test1 *. o

/*************************************** ***************************************
*
* A simple ace client routine
* Function: connect to the specified IP address and send any message to trigger the server. Then, the server receives and displays the data.
* Author: dukejoe)
* Time:
* Blog: http://dukejoe.yeah.net
* QQ: 21807822
* Development Platform: supports AIX 5.3 and Windows XP Home Edition
**************************************** *************************************/
# Include "ACE/inet_addr.h"
# Include "ACE/sock_connector.h"
# Include "ACE/sock_stream.h"
# Include "ACE/log_msg.h"

// Fuzz: Disable check_for_streams_include
# Include "ACE/streams. H"

# If defined (ace_win32 )&&(! Defined (ace_has_standard_cpp_library) |/
(Ace_has_standard_cpp_library = 0) |/
Defined (ace_uses_old_iostreams ))
# Include <stdio. h>
# Else
# Include <string>
# Endif

Int main (INT argc, char * argv [])
{
Ace_inet_addr iaserver;
U_short nport = 5001;
Const char * pserverhost = "10.110.16.45 ";
Int iresult;
Ace_sock_connector scconne;
Ace_sock_stream ssstream;
Char szbuffer [1024];
Char * ptext = "Gao Hongwei QQ: 21807822 ";
Size_t nlength = 0;

Iresult = iaserver. Set (nport, pserverhost );
If (iresult =-1)
Ace_error_return (lm_error, "lookup % s, % P/N", pserverhost, nport), 1 );

If (scconnector. Connect (ssstream, iaserver) <0)
Ace_error_return (lm_error, "% P/N", "Connect ()"), 1 );

Strcpy (szbuffer, ptext );
Ssstream. send_n (szbuffer, strlen (ptext ));
Memset (szbuffer, 0, sizeof (szbuffer ));
Iresult = ssstream. recv_n (szbuffer, 1024 );
Nlength = strlen (szbuffer );
ACE: write_n (ace_stdout, "Recv -->", 9 );
ACE: write_n (ace_stdout, szbuffer, nlength );
ACE: write_n (ace_stdout, "/N", 1 );

Return 0;
}

/*************************************** ***************************************
*
* A simple ACE server routine
* Function: after the client sends any message, the server sends the date string of the current host to the client.
* Author: dukejoe)
* Time:
* Blog: http://dukejoe.yeah.net
* QQ: 21807822
* Development Platform: supports AIX 5.3 and Windows XP Home Edition
**************************************** * ***********************************/# Include <ACE/OS _main.h>
# Include <ACE/ace. h>
# Include <ACE/log_msg.h>
# Include <ACE/sock_acceptor.h>
# Include <ctime>

# Include "ACE/streams. H"

Int displaytime (char * ptime );

Int main (INT argc, char * argv [])
{
Ace_inet_addr ADDR (5001 );
Ace_sock_acceptor server;
Ace_sock_stream stream;
Char szbuffer [1024];

If (server. Open (ADDR) =-1)
{
Ace_debug (lm_debug,
Ace_text ("(% p | % t) % P/N "),
Ace_text ("bind failed ")));
Return 1;
}

While (server. Accept (Stream )! =-1)
{
Ace_inet_addr raddr;
Stream. get_remote_addr (raddr );
Ace_debug (lm_debug, ace_text ("(% p | % t) Connect: % S % d/N"), raddr. get_host_addr (), raddr. get_port_number ()));

Memset (szbuffer, 0, sizeof (szbuffer ));
Displaytime (szbuffer );
Stream. send_n (szbuffer, sizeof (szbuffer ));
Stream. Close ();
}

Server. Close ();

Return 0;
}

Int displaytime (char * ptime)
{
Time_t ntime = 0;
Time (& ntime );
TM * TM1 = localtime (& ntime );
Sprintf (ptime, "% 04d-% 02d-% 02d % 02d: % 02d: % 02d", TM1-> tm_year + 1900, TM1-> tm_mon + 1, TM1-> tm_mday, TM1-> tm_hour, TM1-> tm_min, TM1-> tm_sec );

ACE: write_n (ace_stdout, "current time -->", 13 );
ACE: write_n (ace_stdout, ptime, strlen (ptime ));
ACE: write_n (ace_stdout, "/N", 1 );

Return 0;
}

We use AIX 5.3 as an example to describe the installation configuration on UNIX. Since the system I use does not install the OpenSSL library, so I first downloaded the openssl-0.9.8e.tar.gz download page isHttp://www.openssl.orgDownload and install OpenSSL is easier to make and then make install. Before using ace, should you be familiar with Unix? (What? Unfamiliar? Ace is a relatively advanced topic. If it is a high school after the primary school has not finished reading it, you have to make up for the junior and primary school classes)

To install ace_root on AIX, you must first set ace_root. The method has a statement in setenv. Sh above.

Step 2 also generates config. h like windows. We use AIX 5.3, so I want to include the config-aix-5.x.h file in config. h.

Step 3: Enter the $ {ace_root}/include/makeinclude directory and create a file named platform_macros.gnu, which contains the following line
Include $ (ace_root)/include/makeinclude/platform_aix.gnu. Another method is to use ln-s platform_aix.gnu platform_macros.gnu

Next, create a directory build in the $ {ace_root} directory. Then CD build. Execute ../configure in the build directory. Wait for a while and then make again to generate the ace.

The Installation Process on AIX is here. Next, you can use setenv. Sh to initialize the environment variables. In fact, the two directories named ace_root and LD_LIBRARY_PATH are specified.

1. Set the ace_root variable. Example: ace_root =/Rpt/gaohw/ace_wrappers; export ace_root

2. In the $ {ace_root}/ace directory, create config. h and add the # include "config-aix-5.x.h" statement.
Or do not want to generate the file with Ln-s config-aix-5.x.h config. h

3. In the $ {ace_root}/include/makeinclude directory, create platform_macros.gnu and add include $ (ace_root)/include/makeinclude/platform_aix.gnu
Of course, you can also use ln-s platform_aix.gnu platform_macros.gnu to achieve the same effect.

4. Create a directory build in $ {ace_root }.

5. Click ../configure in build (Note that there must be two points)

6. After configure is successful, make it again.

7. For testing, set LD_LIBRARY_PATH as mentioned above, and then use the source code and makefile above to compile the file. Click the link and run it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.