Besides,

by baigl9sdd on 2012-02-04 18:25:09

From www.acejoy.com, ACE Network Programming Development Forum: Network programming often gives people headaches, with all sorts of bizarre problems popping up unexpectedly, much like Tu Xingsun (a character from Chinese mythology). If you also have to port your code to multiple platforms — wouldn’t that just mean burning the midnight oil until you're alone with your shadow? Of course, experts don't need to worry about it: they just need to look up some materials and familiarize themselves with a few API functions under VxWorks or Solaris, and they’re good to go. But for us ordinary folks, whose skills aren't yet at the level where grass, trees, bamboo, and stones can be turned into swords, does this necessarily mean pulling N all-nighters plus N to the power of N debugging sessions? Not at all! Newton told us: if we could stand on the shoulders of giants, wouldn't we do even better? An ancient Chinese saying goes: "To do a job well, one must first sharpen his tools." If we could find those legendary giants and get our hands on their legendary tools, wouldn't everything fall into place naturally? And at this great moment, ACE was born!

ACE stands for Adaptive Communication Environment. It is a set of freely usable (free?), open-source object-oriented (OO) frameworks. Using it, you can discard the differences between platforms, greatly simplify network programming, reduce the chances of making mistakes, and more—hold on, let's clarify this first.

ACE encapsulates the API interface functions of various operating systems and provides them to programmers in a unified interface format. In other words, you only need to simply call the function formats provided by ACE (these formats are very similar to common system APIs), and ACE will automatically convert them into the functions of the platform you're on: whether it’s VxWorks, Solaris, or of course, the famous WINDOWS and Linux. The implementation method? You can probably guess: it uses a lot of conditional compilation to unify the API functions with similar functionalities across different systems. If there isn't an equivalent, it simulates the functionality; if there is, it simply uses an inline method without sacrificing efficiency. That’s point number one!

Did you expect there to be a second point? ACE applies object-oriented thinking to these functions, refactoring the functionalities of network programming and establishing an object-oriented model. For example, ACE treats one side of a connection as an object and each connection as an object, with previous operations being encapsulated as object functionalities. Don't underestimate this. This allows you to use object-oriented thinking to build applications, and the type protection mechanism of OO can catch a large number of bugs at compile time rather than runtime. Of course, if someone has a particular preference for the C language function style, ACE also provides such function forms to satisfy this unusual taste.

Talking without doing is useless. Let me demonstrate with a small example to silence those skeptical eyes. (Due to space limitations, I will only list the most core code here:

```cpp

int main(int, char *[]) {

ACE_INET_Addr port_to_listen(9999);

ACE_SOCK_Acceptor acceptor;

acceptor.open(port_to_listen, 1);

while (1) {

ACE_SOCK_Stream peer;

ACE_INET_Addr peer_addr;

ACE_Time_Value timeout(10, 0);

if (0 == acceptor.accept(peer, &peer_addr, &timeout, 0)) {

char buffer[4096];

ssize_t bytes_received;

while ((bytes_received = peer.recv(buffer, sizeof(buffer))) != -1) {

peer.send_n(buffer, bytes_received);

}

peer.close();

}

}

return 0;

}

```

In just a few lines of code, a complete server has been implemented: it listens on port 9999, accepts a TCP connection, and echoes back the data sent. If the operation is completed, it disconnects and waits for the next connection, starting the next cycle. By including the necessary header files, adding a few error handling sentences, and placing this code in ACE's compilation environment—whether it’s WINDOWS, Linux, or UNIX—it can be compiled and run.

If ACE's functionality were limited to this, it might not be enough to support its current success: ACE's application in the West has already spread widely across telecommunications, aviation, insurance, military, geography, gaming, and many other fields. In fact, the functionality mentioned above only accounts for about 10% of ACE's code. The remaining part implements even more remarkable features.

ACE integrates various excellent patterns in the communication field, using the portable OS layer functions it has already established (the part mentioned earlier) to build elegant frameworks. These patterns are the accumulated best practices of numerous engineers. In fact, thanks to the open-source philosophy, currently, over 1700 workers and hundreds of core team members worldwide are further developing ACE. You can say that by using ACE, you're not standing on the shoulders of one giant but on the shoulders of over 1700 people worldwide. Therefore, you only need to extend the existing framework, greatly shortening the development process and significantly improving the program's hardware usage efficiency—this has been proven.

ACE mainly provides the following frameworks for network program development:

- Event multiplexing components: The ACE Reactor (reactor) and Proactor (proactor) are extensible object-oriented multiplexers that dispatch application-specific handlers to respond to various types of events based on I/O, timers, signals, and synchronization.

- Service initialization components: The ACE Acceptor (acceptor) and Connector (connector) components decouple automatic and passive initialization tasks from the application-specific tasks performed by communication services once initialization is complete.

- Process and thread management: Provides multi-process and multi-thread derivation and management methods, eliminating platform differences.

- Service configuration components: The ACE Service Configurator (service configurator) supports the configuration of applications whose services can be dynamically assembled at installation time and/or runtime.

- Layered stream components: The ACE Stream component simplifies the development of communication software applications composed of layered services, such as user-level protocol stacks.

- Naming service: The ACE NamingService provides facilities for naming contexts within a single process, shared naming contexts across nodes in a single machine, and network-wide naming contexts.

In addition to these, ACE also provides rich features such as signals, thread safety and synchronization, memory management, etc. ACE has grown into a perfect system, providing exceptionally rich services in network programming.

Would ACE be satisfied with this? Of course not! Currently, ACE is perfecting its advanced distributed computing middleware components and has planned multiple projects to further streamline and develop ACE's functionalities. Therefore, when using ACE, you don't have to worry about the knowledge you've learned depreciating over time—in fact, quite the opposite.

With a sharp sword in hand, you should learn how to use it to maximize its effectiveness. The creator of ACE has written three textbooks for us: a two-volume set of "C++ Network Programming" and a book called "ACE Programmer's Guide," both of which have Chinese translations available. Additionally, there are materials online for reference. If you're interested in ACE's design, it couldn't be simpler: you can browse its entire source code—ACE is completely open-source!

Relevant topic articles:

- http://omag.dreamy.in/a/home/space.php?uid=4421&do=blog&id=337000

- http://www.vu80.com/forum-77-1.html

Relevant topic articles:

- http://www4.stut.edu.tw/project/lifechen/bt/read.php?tid=402405

- http://cyworld.ifensi.com/ps2/diary/diary_view.php?mh_id=2011724970&diary_date=20120128&postid=220697

Relevant topic articles:

- http://blog.sina.com.cn/s/blog_a13499ae010103ft.html

- http://blog.jinti.com/sdmliao/2757808.htm