Skip to content

Installation Instructiosn

General Instructions

One of the following:

  1. npm install corelink-client

Usage Instructions

API reference

API Documentation

TCP Sender and Receiver Walkthrough

Sender Walkthrough

First import corelink

const corelink = require('<corelink-client-repo>/javascript/corelink.lib')

Then define some constants. You will definitely need a server and a cert that authenticates into that server in order to send data.

const config = {
  ControlPort: 20012,
  /*            ControlIP: '127.0.0.1', */
  ControlIP: 'corelink.hpc.nyu.edu',
  autoReconnect: false,
  cert: '<corelink-tools-repo>/config/ca-crt.pem'
}
In order to send data, you will also need to define a workspace that you would like to send data into, a name for the stream you will be using, and a protocol to send data with.
// Setup
const workspace = 'Holodeck'
const protocol = 'tcp'
const datatype = 'distance'
In our example we have a random data function to just generate some sample data, so here it is.
let iter = 0

function randomdata() {
  iter++
  console.log(iter.toString())
  return iter.toString()
}
This is the function that is actually used to send data. The steps in order are 1. Connect to the server using a username/password and the constansts that we defined before 2. Create a sender that you can send data with 3. Send data with that sender (this is the setInterval() function)
const run = async () => {
  let sender
  if (await corelink.connect({ username: 'Testuser', password: 'Testpassword' }, config).catch((err) => { console.log(err) })) {
    sender = await corelink.createSender({
      workspace,
      protocol,
      type: datatype,
      metadata: { name: 'Random Data' },
    }).catch((err) => { console.log(err) })
  }
  setInterval(() => corelink.send(sender, Buffer.from(randomdata())), 1000)
}

run()

Receiver Walkthrough

You always have to import the library.

const corelink = require('<corelink-client-repo>/javascript/corelink.lib')

These are the same constants as the sender

const config = {
        ControlPort: 20012,
        /*      ControlIP: '127.0.0.1', */
        ControlIP: 'corelink.hpc.nyu.edu',
        autoReconnect: false,
        cert: '<corelink-tools-repo>/config/ca-crt.pem'
}
In order to receive data from our stream, we must be on the same workspace and stream name.
const workspace = 'Holodeck'
const protocol = 'tcp'
const datatype = 'distance'
Receiving data is similar to sending it. Here are the steps: 1. Connect to the server using a username/password and the certs from earlier 2. create a receiver 3. Define a function that reacts to changes in the stream id 4. Define a callback function to react to the data received.
const run = async () => {
  if (await corelink.connect({ username: 'Testuser', password: 'Testpassword' }, config).catch((err) => { console.log(err) })) {
    await corelink.createReceiver({
      workspace, protocol, type: datatype, echo: true, alert: true,
    }).catch((err) => { console.log(err) })

    corelink.on('receiver', async (data) => {
      const options = { streamIDs: [data.streamID] }
      await corelink.subscribe(options)
    })

    corelink.on('data', (streamID, data, header) => {
      console.log(streamID, data.toString(), JSON.stringify(header))
    })
  }
}

run()

Source

You can read the code in the examples repository