Archived

This forum has been archived. Please start a new discussion on GitHub.

Writing an ice application with java

Hello !

I try to learn how to use Ice and so I tried to compile and execute the Hello world application discribe in the Ice documentation.

I wrote exactly the Server.cpp file, the compilation on windows was successful but when I execute it I have an "std::bad_alloc à l'emplacement mémoire 0x0012f0b8" error !

The exact line which throws the error is :
Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 1000");

Thank you for your help !
Matthieu

Comments

  • bernard
    bernard Jupiter, FL
    Hi Matthieu,

    Welcome to our forums! It's surprising that you would run out of memory with such a simple C++ program. Did you try any of the demos that comes with Ice?

    Also, check that you're linking with the proper libraries. See http://www.zeroc.com/faq/windowsLibraryMixup.html.

    Cheers,
    Bernard
  • Thank you for your quick answer, I tried to compile and run the hello demo from Ice and it works !!

    I compared therefore the source files :

    - the demo use always the function communicator() instead of initialize a object "Ice::CommunicatorPtr ic = Ice::initialize(argc, argv);". What is this function ?

    - furthermore, the demo use a file called config.client or config.server. What are their utility ? Are they absolutely necessary ?

    Sorry for the langage mistakes, english is not my first langage !
    Matthieu
  • benoit
    benoit Rennes, France
    Hi Matthieu,

    The Ice hello application uses the Ice::Application helper class to initialize the communicator. It also provides other functionalities such as clean shutdown on interrupts, see here for more information on this class.

    Using this class or property configuration files is not required, see demo/Ice/minimal for an example that doesn't use Ice::Application or configuration files.

    Cheers,
    Benoit.
  • Still an out of memory...

    I have still my out of memory error...

    It is possible that this "out of memory" comes from a version problem ? I compile on visual C++ Express 2008 with the Ice Version 3.2.1. I can't change the Ice version because I am improving a existing project using this previous version. Should I install Visual Studio 2005 ?

    Thank you,
    Matthieu

    My file is :

    #include <Ice/Ice.h>
    #include "Affcarre.h"

    using namespace std;

    class Server : public Ice::Application
    {
    public:
    virtual int run(int argc, char* argv[]);
    };

    int main(int argc, char* argv[])
    {
    Server app;
    int status = app.main(argc, argv);
    return status;
    }

    int Server::run(int argc, char* argv[])
    {
    Ice::PropertiesPtr properties = communicator()->getProperties();
    Ice::ObjectAdapterPtr affcarre_adapter = communicator()->createObjectAdapter("Aaffcarre");
    Ice::Identity affcarre_id = communicator()->stringToIdentity("affcarre");
    affcarre_adapter->add(new Affcarre(properties->getProperty("Ice.ServerId")), affcarre_id);
    affcarre_adapter->activate();
    communicator()->waitForShutdown();
    return 0;
    }
  • dwayne
    dwayne St. John's, Newfoundland
    C++ Express 2008 was not a supported compiler for Ice 3.2.1, it was not supported until Ice 3.3. See here for the platform list for Ice 3.2.1. Therefore it is possible that it is a compiler issue. Still it is odd that the Ice demos work and your example does not. Are you using the same build options when building your application as the Ice demos use?
  • Thank you for your answer !

    The error of out of memory disapeard ! It was a problem as Bernard said ! I used the ice.lib and iceutil.lib in debug mod. Then I tried in release mod, and it compile!

    ++
    Matthieu
  • New problem !!

    Hello, I am back with a new problem !

    The out_of_memory problem resolved, I have now a InitializationException at the same line.

    "Exception de première chance à 0x7c812aeb dans Serv_Ex_2_Icar.exe*: Exception Microsoft C++*: Ice::InitializationException à l'emplacement mémoire 0x0012f89c.."

    This error appears on the second line (when I want to create the ObjectAdapter) when compiling this :

    int GridServer::run(int argc, char* argv[])
    {
    Ice::PropertiesPtr properties = communicator()->getProperties();

    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Aname");

    adapter->add(new Name(properties->getProperty("Ice.ServerId")), communicator()->stringToIdentity("name"));

    adapter->activate();

    adapter = communicator()->createObjectAdapter("Acarre");

    adapter->add(new Carre(properties->getProperty("Ice.ServerId")), communicator()->stringToIdentity("carre"));

    adapter->activate();

    communicator()->waitForShutdown();

    return EXIT_SUCCESS;
    }



    I tried in Release mod with the file Ice.lib and IceUtil.lib, and in Debug mod with the files Iced.lib and IceUtild.lib, there is the same error.

    I work with VS 2008 and the Ice 3.3.0 version.

    Thank you,
    Matthieu
  • matthew
    matthew NL, Canada
    Do you have configuration set for the object adapters (ie: Aname.Endpoints and Acarre.Endpoints)? Also, why are you creating two object adapters? That is almost never necessary. See http://www.zeroc.com/faq/multipleOA.html for details.
  • Thank you very much for your answer !

    I switched this line :

    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Aname");

    with this line :

    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("Aname", "tcp -p 10000");


    After that I wanted to use just one adpater. So I created a object adapter then add the two objects :

    adapter->add(new Name(properties->getProperty("Ice.ServerId")), communicator()->stringToIdentity("name"));

    adapter->add(new Carre(properties->getProperty("Ice.ServerId")), communicator()->stringToIdentity("carre"));

    adapter->activate();


    It is correct ?? Because when I use my client, itjust see the first object "name". So I create two adapters with two different port numbers (tcp -p 10000 and tcp - p 10001), and it works.
    But I use a client application, which I didn't developp myself. My project is to improved this former application, so maybe the past team developp the client with several object adapter... It is really a problem to have several object adapters for one server ?


    The port number ("tcp -p 10000") have to be unique : one number for one object adapter ?

    Cheers,
    Matthieu
  • matthew
    matthew NL, Canada
    Matthieu wrote: »
    ....
    It is correct ?? Because when I use my client, itjust see the first object "name".

    From an Ice point of view, what you have done is correct. If your client is only seeing one object, then the client must have some expectation you are not meeting.
    So I create two adapters with two different port numbers (tcp -p 10000 and tcp - p 10001), and it works.
    But I use a client application, which I didn't developp myself. My project is to improved this former application, so maybe the past team developp the client with several object adapter... It is really a problem to have several object adapters for one server ?

    Multiple object adapters means multiple endpoints so it is not ideal.
    The port number ("tcp -p 10000") have to be unique : one number for one object adapter ?

    The ports must be unique, yes.