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)
- Set up PATH / LD_LIBRARY_PATH to include OpenDDS, TAO, ACE, and MPC binaries
- Set up the environment variable DEMO_ROOT to point to the root of this repository
- Generate project files using mwc. Assuming
gnuace
:
mwc.pl -type gnuace node-opendds-rest-demo.mwc
- Build C++ IDL library and
control
application. Again, assuming 'gnuace':
make depend && make
- Build Node.js
server
application
cd server
npm install
cd -
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:$PWD/idl
cd control
./control -DCPSPendingTimeout 3 -DCPSConfigFile ../rtps.ini
- Run the server application
cd server
node main.js -DCPSPendingTimeout 3 -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.