ThingWorx Edge C SDK > How to Set Up an Application > Initializing the Tunnel Manager (Optional) > Create a Tunnel Event Handler (Optional)
Create a Tunnel Event Handler (Optional)
If you are using the Tunneling capability of the C SDK, you may want to create an event handler for any tunneling events. This handler is called when a new tunnel is established or when a tunnel closes. The twTunnelManager also provides functions to list active tunnels and to force a shutdown of an active tunnel.
The signature for a tunnel event callback is as follows:
typedef void (*tunnel_cb) (char started, const char * tid, const char * thingName,
const char * peerName, const char * host, int16_t port, DATETIME startTime,
DATETIME endTime, uint64_t bytesSent, uint64_t bytesRcvd,
const char * type, const char * msg, void * userdata);
The input parameters for this callback function are as follows:
started — Boolean. true if the tunnel is started, false if tunnel has ended.
tid — the unique id of the tunnel
thingName — the name of the Thing this tunnel is targeted at
peerName — the name of the peer user of the tunnel
host — the hostname of the local connection that is tunneled to
port — the port number of the local connection that is tunneled to
startTime — the time the tunnel started (0 if it never started)
endTime — the time the tunnel ended (0 if it hasn't ended yet)
bytesSent — the total number of bytes that were sent to the peer
bytesRcvd — the total number of bytes that were received from the peer
type — the type of the tunnel (tcp, udp, or serial)
userdata — an opaque pointer that was passed in during registration
The definition of the twTunnelManager singleton’s functions can be found in the file src/tunneling/twTunnelManager.h.