The ACE Programmer's Guide

Stephen D. Huston, James C. E. Johnson, Umar Syyid

Mentioned 7

* *An intro guide for ACE beginners, and an authoritative reference for all ACE users. *Foreword by Dr. Douglas C. Schmidt--the original developer of ACE. *ACE is an excellent example of how to design object-oriented software and use C++ to design and write high-performance, easily maintained software systems.

More on Amazon.com

Mentioned in questions and answers.

Plug-in systems in C++ are hard because the ABI is not properly defined, and each compiler (or version thereof) follows its own rules. However, COM on Windows shows that it's possible to create a minimal plug-in system that allows programmers with different compilers to create plug-ins for a host application using a simple interface.

Let's be practical, and leave the C++ standard, which is not very helpful in this respect, aside for a minute. If I want to write an app for Windows and Mac (and optionally Linux) that supports C++ plug-ins, and if I want to give plug-in authors a reasonably large choice of compilers (say less than 2 year old versions of Visual C++, GCC or Intel's C++ compiler), what features of C++ could I count on?

Of course, I assume that plug-ins would be written for a specific platform.

Off the top of my head, here are some C++ features I can think of, with what I think is the answer:

  • vtable layout, to use objects through abstract classes? (yes)
  • built-in types, pointers? (yes)
  • structs, unions? (yes)
  • exceptions? (no)
  • extern "C" functions? (yes)
  • stdcall non-extern "C" functions with built-in parameter types? (yes)
  • non-stdcall non-extern "C" functions with user-defined parameter types? (no)

I would appreciate any experience you have in that area that you could share. If you know of any moderately successful app that has a C++ plug-in system, that's cool too.

Carl

ACE has a cross platform plug-in architecture.

Check out:

  1. ACE DLL
  2. ACE DLL Manager

I would suggest checking out the book
The ACE Programmer's Guide

Can anybody provide me some sample example on Client and server connection using sockets in C++. I have gone through some tutorials now i want to implement it. How to start ?

A good C++ networking library is ACE. The only problem is that there aren't any good tutorials online that I have found. This book is pretty good though.

Can anyone find an example of a simple server/client thing? I'm willing to use any C++ library or even Winsocks it self. I've Googled around but want some opinion on a good article for beginners/sites.

I like ACE. It is a pretty large library but there are some core classes that are really easy to use for beginning network programming.

Here's a really good book for ACE too. Ace Programming Guide

I have never written any IPC C++ on Linux before.

My problem is that I will have multiple clients (writers), and a single server (reader). All of these will be on the same machine. The writers will deliver chunks of data (a string/struct) to the reader. The reader will then read them in FIFO and do something with them.

The types of IPC on Linux are either Pipes or Sockets/Message Queues as far as I can tell.

I was just wondering if someone could recommend me a path to go down. I'm leaning towards sockets, but I have no real basis for that. Is there anything I should read/understand before embarking on this journey?

Thanks

Try to take a look at ACE (Adaptive Communication Environment). The ACE libraries are free available, very mature and cross platform. Unfortunately a good documentation is not, i would recommend this book to look for a good solution. You might try to take a look at this tutorial to get a feel of the patterns (at the end of the document). ACE uses a bunch of patterns to deal very successfully and efficient with those problems especially in a networked context, so it should be a good start to scope for good patterns and methods to use.

Especially Ace_Task using the Message_Queue allow to do what you need.

Im trying to develope a program that uses ACE library for networking. When i tried to allocate new ACE_TP_Reactor it crash (program building successfully but when it started to execute dll throw an unhandled exception)

ACE_Reactor_Impl* imp = 0;
imp = new ACE_TP_Reactor();

here is stack:

    GameServer.exe!WorldSocketMgr::StartNetwork(unsigned short port, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & address) Line 103   C++

ace.dll!ACE_TP_Reactor::ACE_TP_Reactor(ACE_Sig_Handler * sh, ACE_Abstract_Timer_Queue<ACE_Event_Handler *> * tq, bool mask_signals, int s_queue) Line 102   C++ <<new ACE_TP_REACTOR

ace.dll!ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >::ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >(ACE_Sig_Handler * sh, ACE_Abstract_Timer_Queue<ACE_Event_Handler *> * tq, int disable_notify_pipe, ACE_Reactor_Notify * notify, bool mask_signals, int s_queue) Line 485   C++

ace.dll!ACE_Select_Reactor_Impl::ACE_Select_Reactor_Impl(bool ms) Line 134  C++

[External Code] 

ace.dll!ACE_Handle_Set::ACE_Handle_Set() Line 95    C++

it crashes when program tried to execute this->reset (); which in

ACE_Handle_Set::ACE_Handle_Set (void)
{
this->reset ();
}

here is the values of stack on ace_handle_set

-  this 0x00ed8e00 {size_=??? max_handle_=??? mask_={fd_count=??? fd_array=0x00ed8e0c {???, ???, ???, ???, ???, ...} } } ACE_Handle_Set *
  size_ <Unable to read memory> 
  max_handle_ <Unable to read memory> 
+  mask_ {fd_count=??? fd_array=0x00ed8e0c {???, ???, ???, ???, ???, ???, ???, ???, ???, ???, ???, ???, ???, ...} } fd_set

Edit: The problem is about all classes about ace for example when i tried to create a ACE_Select_Reactor, ACE_TP_Reactor and etc. it all crashed i think it can be about DLL but i used all libraries and dlls.

thanks for your help.

You are not using the ACE Reactor correctly, look at the ACE Programmers Guide, section 7.7, that explains how to use it.

I am trying to write a program that sends stream packets to a certain listener (I am using my localhost) in UDP, using ACE. This is in order to test my program that receives a stream of UDP datagrams from a remote peer. So far I have managed to simulate a stream, but I don't know how to receive data using a connection of a real network.

This is a code example that sends 60 packets for the localhost, will that be enough for a sender?

int SendDatagram() 
{ 
    const char* message = "this is a message!\n"; 

    ACE_INET_Addr  sender    (27016, ACE_LOCALHOST); 
    ACE_INET_Addr  listener    (27015, ACE_LOCALHOST); 
    ACE_SOCK_DGRAM udp        (sender); 


    ssize_t sent;
    char buffer[BUFSIZ]; 
    size_t size = sizeof(buffer); 
    for (int i = 0; i < 60 ; i++)
    {
        sent = udp.send(message, ACE_OS_String::strlen(message) + 1, listener); 
        if (sent == -1) 
        { 
            ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%p\n"), ACE_TEXT("send")), -1); 
        } 
        cout << "sent:     " << sent << " bytes" << endl;
    }

    udp.close(); 

    return 0; 
} 

Check chapter 9 of the ACE Programmers Guide (see http://www.amazon.com/exec/obidos/ASIN/0201699710/theaceorb-20) for how UDP works with ACE. See ACE_wrappers/examples/APG/Misc_IPC for the code that belongs to that section.

I am desining an update server. The general design is:

  1. Clients connect to Server
  2. Server initializes Clients
  3. <some calculation of the server side>
  4. Server sends all Clients results
  5. Clients do not send to Server anything, just recieve server's update

Items 3-5 are repeated. How can I implemented that logic on C++?

Beside Boost.Asio you can try to use ACE framework.

ACE implements many network design patterns (Reactor and Proactor for example). Though the documentation may not be enough the ACE Programming Guide book provides a extremely good documentation about ACE functionality and how to use ACE efficiently. I find ACE to be extremely powerful for creating portable client server applications.