rt-tcp-utils

0.0.1 • Public • Published

rt-tcp-utils

Utilities for communicating between a JavaScript application and a C++ real-time application created with DevOps Model RealTime or DevOps Code RealTime.

Feel free to extend tcp-server.js to cover your needs. Pull requests are welcome!

Usage

Assuming that the real-time application you want to communicate with runs on localhost on port 9911 you define a TCP server like this:

const tcpServer = require('./tcp-server')('localhost', 9911);

To also be able to receive events sent by the application register a callback function and start listen to events on a port (2234 is the default but can of course be replaced):

tcpServer.setEventReceivedCallback(msgReceived);
tcpServer.startListenForEvents(2234) // Receive TCP requests from RT app on port 2234
.then((data) => {
    console.log("Ready to receive TCP requests");    
});

The callback function msgReceived will be called whenever the real-time application sends out an event. It has an object as argument that contains properties according to the TCPServer documentation. For example:

if (msg.port == "trafficLight") {
	if (msg.event == "red") {
		// Event "red" received on the "trafficLight" port
		// ...
	}
}

To send an event call a function on the tcpServer object. For example:

tcpServer.sendEvent('pedestrian', 'trafficLight'); // Send event "pedestrian" on the "trafficLight" port

Example

This Code RealTime application uses rt-tcp-utils.

Package Sidebar

Install

npm i rt-tcp-utils

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

9.34 kB

Total Files

4

Last publish

Collaborators

  • hcl-rtist