Home › Forum › SOFA › Programming with SOFA › SceneLoaderXML Node initialization failed.
- This topic has 13 replies, 2 voices, and was last updated 6 years, 11 months ago by bgarcial.
-
AuthorPosts
-
1 December 2017 at 20:27 #10201bgarcialBlocked
I built a SOFA plugin and I have a component named ZMQServerComponent.
My structure directory is the following way:
bgarcial@elpug ‹ v17.06 ●● › : ~/workspace/sofa/src/applications/plugins/ZeroMq [0] % tree . ├── CMakeLists.txt ├── initZeroMq.cpp ├── initZeroMq.h ├── Python │ └── server.py ├── README.md ├── Test.scn ├── ZMQServerComponent.cpp └── ZMQServerComponent.h 1 directory, 10 files bgarcial@elpug ‹ v17.06 ●● › :
My component. initially (although this is not relevant for now) create a zeroMQ socket in a specific port.
My
ZMQServerComponent.h
in which I define my component is:#include <sofa/core/behavior/BaseController.h> //#include "Client.h" #include <zmq.hpp> namespace sofa { namespace component { namespace controller { class ZMQServerComponent : public sofa::core::behavior::BaseController { public: SOFA_CLASS(ZMQServerComponent, sofa::core::behavior::BaseController); ZMQServerComponent (); virtual ~ZMQServerComponent (); void receiveRequests(); void sendReplyToClient(); void init(); }; } } }
My
ZMQServerComponent.cpp
is:#include "ZMQServerComponent.h" #include <sofa/core/ObjectFactory.h> #include <zmq.hpp> #include <iostream> using std::cout; using std::endl; namespace sofa { namespace component { namespace controller { zmq::context_t context (1); zmq::socket_t socket (context, ZMQ_REP); ZMQServerComponent::ZMQServerComponent(){ cout << "Creating socket zeroMQ ..."<<endl; socket.bind("tcp://*:5555"); } void ZMQServerComponent::receiveRequests() { zmq::message_t request; // Wait for next request from client socket.recv(&request); std::string incomingMessage = std::string(static_cast<char *>(request.data()), request.size()); std::cout << "Incoming message from client" << incomingMessage << std::endl; // Do some work sleep(1); } void ZMQServerComponent::sendReplyToClient() { // Send reapplications/plugins/ZeroMq/CMakeFiles/ZeroMq.dir/main.cpp.oply back to client zmq::message_t reply (20); memcpy (reply.data(), "Hello Client", 20); socket.send(reply); } void ZMQServerComponent::init(){ ZMQServerComponent z; z.receiveRequests(); z.sendReplyToClient(); } ZMQServerComponent::~ZMQServerComponent() { } // int ZeroMqComponentClass = sofa::core::RegisterObject("This component does nothing.").add<ZeroMqComponent>(); int ZMQServerComponentClass = core::RegisterObject("This component create a Socket.").add<ZMQServerComponent>(); SOFA_DECL_CLASS(ZMQServerComponent) } } }
My initZeroMq.h is:
#ifndef INITZEROMQ_H #define INITZEROMQ_H #include <sofa/helper/system/config.h> #ifdef SOFA_BUILD_ZEROMQ #define SOFA_ZeroMq_API SOFA_EXPORT_DYNAMIC_LIBRARY #else #define SOFA_ZeroMq_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif /** mainpage This is the main page of the doxygen documentation for MyPlugin. */ #endif
My initZeroMq.cpp is:
#include "initZeroMq.h" #include <sofa/helper/system/config.h> #ifndef WIN32 #define SOFA_EXPORT_DYNAMIC_LIBRARY #define SOFA_IMPORT_DYNAMIC_LIBRARY #define SOFA_ZEROMQPLUGIN_API #else #ifdef SOFA_BUILD_ZEROMQPLUGIN #define SOFA_ZEROMQPLUGIN_API SOFA_EXPORT_DYNAMIC_LIBRARY #else #define SOFA_ZEROMQ_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif #endif /* #ifdef WIN32 // BUGFIX(Jeremie A. 02-05-2009): put OpenHaptics libs here instead of the project file to work around a bug in qmake when there is a space in an environment variable used to look-up a library #pragma comment(lib,"hl.lib") #pragma comment(lib,"hd.lib") #pragma comment(lib,"hdu.lib") #endif */ namespace sofa { namespace component { //Here are just several convenient functions to help user to know what contains the plugin extern "C" { SOFA_ZEROMQPLUGIN_API void initExternalModule(); SOFA_ZEROMQPLUGIN_API const char* getModuleName(); SOFA_ZEROMQPLUGIN_API const char* getModuleVersion(); SOFA_ZEROMQPLUGIN_API const char* getModuleLicense(); SOFA_ZEROMQPLUGIN_API const char* getModuleDescription(); SOFA_ZEROMQPLUGIN_API const char* getModuleComponentList(); } void initExternalModule() { // Here is the place to write initialisation code, that will be executed // before any component is created. } const char* getModuleName() { return "Plugin zeroMQ"; } const char* getModuleVersion() { return "0.1"; } const char* getModuleLicense() { return "LGPL"; } const char* getModuleDescription() { return "Network communication from SOFA and external enities via zeroMQ sockets"; } const char* getModuleComponentList() { // Comma-separated list of the components in this plugin, empty for now return ""; } } } SOFA_LINK_CLASS(ZMQServerComponent)
And in my
CMakeLists.txt
I’ve add the lzmq flag to build the zeroMQ libraries. Their content is:cmake_minimum_required(VERSION 3.1) project(ZeroMq) set(HEADER_FILES ZMQServerComponent.h ) set(SOURCE_FILES ZMQServerComponent.cpp ) set(EXTRA_FILES README.md ) find_package(SofaFramework REQUIRED) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES}) target_link_libraries(${PROJECT_NAME} -lzmq ${} SofaCore) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_ZeroMq") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..") install(TARGETS ZeroMq RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
Until this point I’ve build the plugin and component via
cmake-gui ../../src
andmake -j7
and all it’s works.Next, I’ve add some basic scene in a
Test.scn
file:<Node name=”root”>
<ZMQServerComponent name=”test” />
</Node>Then, I execute sofa and I’ve add the
Test.scn
file and I get this error:How to can I interpret this error, in relation to compose or construct a scene well formed and can I execute it in SOFA with the order to show some message.
The idea which I want, is integrate the component and scene in SOFA and after work with zeroMQ apis.
Any orientation is highly appreciated
Best Regards1 December 2017 at 20:37 #10202ErwanDouailleBlockedDoes your plugin is loaded ?
+ <RequiredPlugin name='ZeroMq' />
You can also check in runsofa, there is a menu named plugins.[Off topic]
May I can know the reason why you try to implement zmq instead of using the Communication plugin ? 🙂1 December 2017 at 22:23 #10203bgarcialBlockedI’ve add the
<RequiredPlugin name='ZeroMq' />
directive and the sceneTest.scn
is loaded without errors from SOFA. Thanks for it 🙂Now, I have another error, but is my code in my constructor class
ZMQServerComponent
in myZMQServerComponent.cpp
file.Apparently the plugin or the scene enter to my
ZMQServerComponent
constructor two times …
Well, this is another history or anecdotebgarcial@elpug : ~/workspace/sofa/build/v17.06/bin [0] % ./runSofa [ERROR] [PluginManager] Plugin loading failed (/home/bgarcial/workspace/sofa/build/v17.06/lib/libZeroMq.so): function initExternalModule() not found Creating socket zeroMQ ... Creating socket zeroMQ ... terminate called after throwing an instance of 'zmq::error_t' what(): Address already in use ########## SIG 6 - SIGABRT: usually caused by an abort() or assert() ########## -> /home/bgarcial/workspace/sofa/build/v17.06/lib/libSofaHelper.so.17.06.02(sofa::helper::BackTrace::dump()+0x23) [0x7f5a09015d53]
[Off topic]
May I can know the reason why you try to implement zmq instead of using the Communication plugin ? ?I will want ask/talk with you in relation to Communication Plugin and for it, I did re-open my last thread/question in which you ask to me some interest questions about of use of Communications plugin and their possibilities and limitations. In this thread I will answer to you
Also, many thanks for your help 🙂
1 December 2017 at 22:58 #10204ErwanDouailleBlockedI’ve add the <RequiredPlugin name=’ZeroMq’ /> directive and the scene Test.scn is loaded without errors from SOFA. Thanks for it ?
Cool !
Apparently the plugin or the scene enter to my ZMQServerComponent constructor two times …
Well, this is another history or anecdote`
bgarcial@elpug : ~/workspace/sofa/build/v17.06/bin
[0] % ./runSofa[ERROR] [PluginManager] Plugin loading failed (/home/bgarcial/workspace/sofa/build/v17.06/lib/libZeroMq.so): function initExternalModule() not found
Creating socket zeroMQ …
Creating socket zeroMQ …
terminate called after throwing an instance of ‘zmq::error_t’
what(): Address already in use########## SIG 6 – SIGABRT: usually caused by an abort() or assert() ##########
-> /home/bgarcial/workspace/sofa/build/v17.06/lib/libSofaHelper.so.17.06.02(sofa::helper::BackTrace::dump()+0x23) [0x7f5a09015d53]`It looks like you are creating two sockets by reading
Creating socket zeroMQ ... Creating socket zeroMQ ...
In your component constructor you create a socket on port
socket.bind("tcp://*:5555");
For the first instance, everything works well. But for the second one, it gonna try to bind on port 5555 but it´s already bind by the first instance. Then it crash.
Try to create only one or fix the bind issue like giving the port as an argument.[Off topic]
Cool, we want to share and improve this plugin. Let us know if you want to code in it 😉1 December 2017 at 23:39 #10206bgarcialBlockedIn your component constructor you create a socket on port
socket.bind(“tcp://*:5555”);
For the first instance, everything works well. But for the second one, it gonna try to bind on port 5555 but it´s already bind by the first instance. Then it crash.
Try to create only one or fix the bind issue like giving the port as an argument.I try pass just the port as a parameter of this way:
ZMQServerComponent::ZMQServerComponent(){ cout << "Creating socket zeroMQyyy ..."<<endl; socket.bind("5555"); }
And now does not try create the socket two times but, apparently my argument is not suited …
[ERROR] [PluginManager] Plugin loading failed (/home/bgarcial/workspace/sofa/build/v17.06/lib/libZeroMq.so): function initExternalModule() not found Creating socket zeroMQyyy ... terminate called after throwing an instance of 'zmq::error_t' what(): Invalid argument ########## SIG 6 - SIGABRT: usually caused by an abort() or assert() ########## -> /home/bgarcial/workspace/sofa/build/v17.06/lib/libSofaHelper.so.17.06.02(sofa::helper::BackTrace::dump()+0x23) [0x7f303a2a1d53] -> /home/bgarcial/workspace/sofa/build/v17.06/lib/libSofaHelper.so.17.06.02(sofa::helper::BackTrace::sig(int)+0x19c) [0x7f303a2a209c]
4 December 2017 at 09:00 #10208ErwanDouailleBlockedsocket.bind("5555");
to :
socket.bind("tcp://*:5555");
4 December 2017 at 17:19 #10210bgarcialBlockedBefore, I was passing the port argument exactly as you told me.
In your component constructor you create a socket on port
socket.bind(“tcp://*:5555”);
For the first instance, everything works well. But for the second one, it gonna try to bind on port 5555 but it´s already bind by the first instance. Then it crash.
Try to create only one or fix the bind issue like giving the port as an argumentCurrently I have of this way:
socket.bind("tcp://*:5555");
And I don’t know the reason why the socket is created twice. I am creating the socket in my constructor class ZMQServerComponent, is possible that by some reason this be called two times?
4 December 2017 at 21:13 #10211bgarcialBlockedHi @erwandouaille I’ve separated from the constructor class the socket creation and my component with zeroMQ basics works. I include it inside of a function which I execute in the
ZMQServerComponent::init()
methodWhen I’ve add my Test.scn file sample I can create the socket, despite of some error
When I send a client message from a external client application, in my server sofa I get this:
bgarcial@elpug : ~/workspace/sofa/build/v17.06 [0] % ./bin/runSofa [ERROR] [PluginManager] Plugin loading failed (/home/bgarcial/workspace/sofa/build/v17.06/lib/libZeroMq.so): function initExternalModule() not found Creating socket zeroMQ ... Incoming message from client Hola servidor C++.
From my client application the server response and the CLI is:
bgarcial@elpug ‹ master ●● › : ~/CLionProjects/zeroMQ_C++_Client-Python_Server/Python [1] % python client.py Connecting to hello world server… Received reply b'Hello Client\x00unknown' (cnvss_tests) bgarcial@elpug ‹ master ●● › :
Do you have an idea about of
ERROR] [PluginManager] Plugin loading failed (/home/bgarcial/workspace/sofa/build/v17.06/lib/libZeroMq.so): function initExternalModule() not found
This is my libZeroMq.so which is packed into SOFA (product of build process of my plugin) but I unknown the insights of situation
[OffTopic]
I am try build the SOFACommunication plugin to know more about it and test the samples, but I am setup the environment libs due to I have some problems installing them.Thanks for your support.
6 December 2017 at 12:33 #10213ErwanDouailleBlockedSorry didn´t your latest post.
ERROR] [PluginManager] Plugin loading failed (/home/bgarcial/workspace/sofa/build/v17.06/lib/libZeroMq.so): function initExternalModule() not found
It crashed because you didn´t properly describe your plugin. As I understand from this error message. Ensure your plugins looks like this : https://www.sofa-framework.org/community/doc/programming-with-sofa/start-coding/create-your-plugin/
[OffTopic]
I am try build the SOFACommunication plugin to know more about it and test the samples, but I am setup the environment libs due to I have some problems installing them
Live chat ? What is your problem with libs ? Linux ? Windows (never tested it on win) ?
6 December 2017 at 21:15 #10215bgarcialBlockedLive chat ? What is your problem with libs ? Linux ? Windows (never tested it on win) ?
Hi @erwandouaille, are problems about of libs and configuration settings in my Ubuntu laptop.
I will have to update my sources repositories in relation to install the requirements packages.Additionally, I am testing and learning how to create a component, associate it a scene and send data components from SOFA. For this last thing I’m using ZMQ.
Of this way I want know a few more of SOFA and ZMQ initially.You know about of ZMQ and leverage this, I take the audacity of ask to you the following:
Could you please support me in this inconvenience in relation to send data component via zockets ZWQ.6 December 2017 at 21:28 #10216ErwanDouailleBlockedHi @erwandouaille, are problems about of libs and configuration settings in my Ubuntu laptop.
I will have to update my sources repositories in relation to install the requirements packages.Most of recent ubuntu release have the libs in their repository. Which ubuntu version are you running ?
Additionally, I am testing and learning how to create a component, associate it a scene and send data components from SOFA. For this last thing I’m using ZMQ.
Of this way I want know a few more of SOFA and ZMQ initially.Cool !
You know about of ZMQ and leverage this, I take the audacity of ask to you the following:
Could you please support me in this inconvenience in relation to send data component via zockets ZWQ.IMO, some part of the answer is in : https://www.sofa-framework.org/community/doc/programming-with-sofa/start-coding/create-your-plugin/
For the received message you have to change the way you convert the message, i guess. But i didn´t use python with zmq so i can´t help you more than this.
Otherwise, there is an already existing c++ client here : https://github.com/SofaDefrost/sofa/tree/sofaCommunication/applications/plugins/Communication/examples/ZMQ/primitives/SenderJust compile it and change the port you want to listen on.
7 December 2017 at 17:40 #10218bgarcialBlockedFor the received message you have to change the way you convert the message, i guess. But i didn´t use python with zmq so i can´t help you more than this.
Otherwise, there is an already existing c++ client here : https://github.com/SofaDefrost/sofa/tree/sofaCommunication/applications/plugins/CommunicatioHi @erwandouaille, I am using the C++ client and in my question I show the process, but the response that I get is similar. Apparently the response is a string strange of the same way in pyhton client.
14 December 2017 at 12:11 #10227ErwanDouailleBlockedSorry didn’t see this answer.
That’s weird. Did you try using my C++ client + the server ?
Just to ensure my cpp files are working well on your machine ?
If both works perfectly together, let me know I will investigate your code in details.14 December 2017 at 22:45 #10232bgarcialBlockedHi @erwandouaille I am using to c++ client basic script sample of zeroMQ website, which is too similar to you c++ clients which you show me here
My zeroMQ sockets implementation works to send C++ native data type but does not works for Sofa Data types.
For the moment I don’t need work with Sofa Data types then the clients and server in zeroMQ that I have it’s works
My problem is to send Sofa Data types via zeroMQ sockets
-
AuthorPosts
- You must be logged in to reply to this topic.