Example : Using a Socket Adapter in C
====================================

This example illustrates how to use RTI Routing Service Adapter SDK to create an
adapter that writes and reads data from sockets. Routing Service allows you to
bridge data from different data domains with a pluggable adapter interface.

To learn how to implement your own adapter, you can follow this example and
others in this folder to inspect the code that is distributed with these
adapters. The socket adapter can read data from sockets with a specific format
and provide it to Routing Service, or receive data from Routing Service and
write it into sockets.

In this example, we will first write topic data (a colored square)
into a socket and then use that socket to write it back into Connext DDS, allowing
us to see the packages using wireshark.

Steps
------

1. Compile the Adapter in adapters/socket/src:

    - Set NDDSHOME to point to your RTI Connext DDS installation.

    - On Linux and macOS systems, enter:

        cd <path to examples>/routing_service/adapters/socket/make
        make -f Makefile.<architecture>

    The adapter shared library, libsocketadapter.so, will be copied to
    <path to examples>/routing_service/adapters/socket.

    - On Windows systems:
        Open the Visual Studio solution under
        <path to examples>/routing_service/adapters/socket/windows.
        For example, if you are using Visual Studio 2013, open
        socketadapter-vs2013.sln. Build the solution. The adapter shared
        library, socketadapter.dll, will be copied to <path to examples>/routing_service/adapters/socket.

    - On QNX systems you must set the environment variables QNX_HOST and QNX_TARGET.
      For example:

          setenv QNX_BASE /opt/qnx660
          setenv QNX_HOST ${QNX_BASE}/host/linux/x86
          setenv QNX_TARGET ${QNX_BASE}/target/qnx6

2. Route data from Connext DDS to a socket:

    - Edit <path to examples>/routing_service/shapes/socket_bridge.xml
      and look for <route name=”square_socket”> within <routing service name=”dds_to_socket”>.
      In the <property> tag, change the Host and Port values to match with socket_to_dds.
          
    - Start Routing Service by entering the following in a command shell:

        cd <NDDSHOME>
        bin/rtiroutingservice
            -cfgsocket <path to examples>/routing_service/shapes/socket_bridge.xml \
            -cfgName dds_to_socket

    Routing service should be now routing squares from domain 0 to a socket in the tcp port 8112.

3. Route data from a socket to Connext DDS:

    - Start Routing Service by entering the following in a command shell:

        cd <NDDSHOME>
        bin/rtiroutingservice
                -cfgFile <path to examples>/routing_service/shapes/socket_bridge.xml \
                -cfgName socket_to_dds


3. Open Shapes Demo, and publish and subscribe to squares.

    You should see squares being received by Shapes Demo with a little delay from the original square.
    
    There should be a little delay and shouldn't be as smooth as using DDS as TCP is slower than UDP.

    You can also use wireshark using tcp.port==8112 to see the packages.