This is a very simple example of using node-opendds (the Node.js bindings for OpenDDS) in order to build a custom bridge between RESTful web services and DDS. The premise of this demo is based on a multiplayer game in which a single C++ 'control' application communicates using DDS with several Node.js 'server' bridge applications. Players may simply point a javascript capable browser at a running server (default port of 3210) in order to pull down a lightweight client web application in order to join the game.
The emphasis of this demo is to show how simple HTTP requests ('PUT', 'GET', 'DELETE') may be used to interact with DDS sample instances via a bridgine application, and as a result polling is used in order to get notifications of changes to game states. For real-world applications, this is obviously not ideal and some kind of asynchronous push notification (e.g. websockets) would most likely be used for the sake of performance and user experience.
- Set up the OpenDDS environment variables (DDS_ROOT, TAO_ROOT, ACE_ROOT etc)
- Update PATH to include OpenDDS/bin
- Update LD_LIBRARY_PATH (or similar) to include lib subdirectories of ACE_ROOT and DDS_ROOT
- Note: the preceeding steps can be done in one command by sourcing OpenDDS's setenv.sh/setenv.cmd script
- Set the environment variable DEMO_ROOT to point to the root of this repository
- Generate project files using mwc. Assuming
gnuace
:
opendds_mwc.pl node-opendds-rest-demo.mwc
- Build C++ IDL library and
control
application. Again, assuming 'gnuace':
make depend && make
Note: make depend
is only needed if IDL / source code will be modified after its built
* For Visual C++: build the generated solution
7. Build Node.js server
application
cd server
npm install
cd ..
- For Visual C++: add
--debug --lib_suffix=d
afternpm install
if using a Debug configuration
For this step, you'll likely want to spawn multiple consoles / terminals in order to run both the client and the server at the same time. Generally speaking, you hopefully shouldn't ever need to restart the control application.
- Run the control application. Assuming some flavor of Linux/UNIX:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DEMO_ROOT/lib
control/control -DCPSConfigFile rtps.ini
And for Windows:
set PATH=%PATH%;%DEMO_ROOT%\lib
control\control -DCPSConfigFile rtps.ini
- Run the server application
cd server
node main.js -DCPSConfigFile ../rtps.ini
- Navigate a javascript-enabled web browser to http://localhost:3210
Same as the steps above, though you will obviously need to launch multiple 'server' applications running on different
ports (use the --port <PORT>
option) as well as have multiple browser tabs open to connect to each of the servers.
Additionally, this demo also exists in a form that supports websockets interactions between client and server. Check out the websockets
branch if you're interested in seeing those improvements.