|
| 1 | +--- |
| 2 | +seoTitle: ACE – Adaptive Communication Environment C++ Reference |
| 3 | +description: "ACE (Adaptive Communication Environment) reference for C++ networked and real-time systems. Covers reactor pattern, proactor, sockets, threading, and service configuration." |
| 4 | +keywords: "ACE, Adaptive Communication Environment, C++ networking, reactor pattern, proactor, C++ sockets, real-time systems, TAO CORBA, C++ middleware, VR-Rathod, Code-Note, code note vr, vr book" |
| 5 | +displayTitle: ACE (Adaptive Communication Environment) |
| 6 | +--- |
| 7 | + |
| 8 | +- # History |
| 9 | + collapsed:: true |
| 10 | + - **Who**: Created by Douglas C. Schmidt at Washington University, St. Louis. |
| 11 | + - **Why**: To provide a portable, reusable C++ framework for building high-performance networked and real-time systems using well-known design patterns (Reactor, Proactor, Active Object). |
| 12 | + - **When**: Development started in the early 1990s. Widely used in telecom, defense, and financial systems. |
| 13 | + |
| 14 | +- # Introduction |
| 15 | + collapsed:: true |
| 16 | + - ## What is ACE? |
| 17 | + - An open-source C++ framework for building concurrent, networked, and real-time systems. |
| 18 | + - Implements classic concurrency and networking patterns: Reactor, Proactor, Active Object, Half-Sync/Half-Async. |
| 19 | + - Website: [www.dre.vanderbilt.edu/~schmidt/ACE.html](http://www.dre.vanderbilt.edu/~schmidt/ACE.html) |
| 20 | + - |
| 21 | + - ## Advantages |
| 22 | + collapsed:: true |
| 23 | + - Battle-tested in mission-critical systems (telecom, defense, finance). |
| 24 | + - Implements well-known design patterns for concurrent programming. |
| 25 | + - Highly portable across OS and compilers. |
| 26 | + - Pairs with TAO for CORBA-based distributed systems. |
| 27 | + - |
| 28 | + - ## Disadvantages |
| 29 | + collapsed:: true |
| 30 | + - Very steep learning curve — complex API. |
| 31 | + - Large codebase with many abstractions. |
| 32 | + - Modern alternatives (Boost.Asio, POCO) are often simpler for new projects. |
| 33 | + - Documentation can be sparse for advanced features. |
| 34 | + |
| 35 | +- # Installation & Setup |
| 36 | + collapsed:: true |
| 37 | + - ## apt (Ubuntu) |
| 38 | + - ```bash |
| 39 | + sudo apt install libace-dev |
| 40 | + ``` |
| 41 | + - |
| 42 | + - ## Build from Source |
| 43 | + - ```bash |
| 44 | + git clone https://github.com/DOCGroup/ACE_TAO.git |
| 45 | + cd ACE_TAO/ACE |
| 46 | + # Set ACE_ROOT environment variable |
| 47 | + export ACE_ROOT=$(pwd) |
| 48 | + make |
| 49 | + ``` |
| 50 | + - |
| 51 | + - ## CMake |
| 52 | + - ```cmake |
| 53 | + find_package(ACE REQUIRED) |
| 54 | + target_link_libraries(MyApp ACE::ACE) |
| 55 | + ``` |
| 56 | + |
| 57 | +- # Core Concepts |
| 58 | + collapsed:: true |
| 59 | + - ## TCP Echo Server (Reactor Pattern) |
| 60 | + collapsed:: true |
| 61 | + - ```cpp |
| 62 | + #include <ace/SOCK_Acceptor.h> |
| 63 | + #include <ace/SOCK_Stream.h> |
| 64 | + #include <ace/INET_Addr.h> |
| 65 | + |
| 66 | + ACE_INET_Addr addr(5000); |
| 67 | + ACE_SOCK_Acceptor acceptor(addr); |
| 68 | + ACE_SOCK_Stream client; |
| 69 | + |
| 70 | + acceptor.accept(client); |
| 71 | + |
| 72 | + char buf[1024]; |
| 73 | + ssize_t n = client.recv(buf, sizeof(buf)); |
| 74 | + client.send(buf, n); // echo back |
| 75 | + client.close(); |
| 76 | + ``` |
| 77 | + - |
| 78 | + - ## TCP Client |
| 79 | + collapsed:: true |
| 80 | + - ```cpp |
| 81 | + #include <ace/SOCK_Connector.h> |
| 82 | + #include <ace/SOCK_Stream.h> |
| 83 | + #include <ace/INET_Addr.h> |
| 84 | + |
| 85 | + ACE_INET_Addr server("localhost", 5000); |
| 86 | + ACE_SOCK_Connector connector; |
| 87 | + ACE_SOCK_Stream stream; |
| 88 | + |
| 89 | + connector.connect(stream, server); |
| 90 | + |
| 91 | + const char* msg = "Hello ACE!"; |
| 92 | + stream.send(msg, strlen(msg)); |
| 93 | + |
| 94 | + char buf[1024]; |
| 95 | + ssize_t n = stream.recv(buf, sizeof(buf)); |
| 96 | + buf[n] = '\0'; |
| 97 | + ACE_DEBUG((LM_INFO, "Received: %s\n", buf)); |
| 98 | + |
| 99 | + stream.close(); |
| 100 | + ``` |
| 101 | + - |
| 102 | + - ## Threading (ACE_Thread_Manager) |
| 103 | + collapsed:: true |
| 104 | + - ```cpp |
| 105 | + #include <ace/Thread_Manager.h> |
| 106 | + |
| 107 | + void* worker(void*) { |
| 108 | + ACE_DEBUG((LM_INFO, "Thread running\n")); |
| 109 | + return nullptr; |
| 110 | + } |
| 111 | + |
| 112 | + ACE_Thread_Manager::instance()->spawn(worker); |
| 113 | + ACE_Thread_Manager::instance()->wait(); // wait for all threads |
| 114 | + ``` |
| 115 | + |
| 116 | +- # More Learn |
| 117 | + - [ACE Official Site](http://www.dre.vanderbilt.edu/~schmidt/ACE.html) |
| 118 | + - [ACE GitHub](https://github.com/DOCGroup/ACE_TAO) |
| 119 | + - [ACE Programmer's Guide](http://www.dre.vanderbilt.edu/~schmidt/PDF/ACE-tutorial.pdf) |
| 120 | + - [Pattern-Oriented Software Architecture (POSA) books](https://www.dre.vanderbilt.edu/~schmidt/POSA/) |
0 commit comments