Installation Instructiosn
General Instructions
One of the following:
npm install corelink-client
Importing
Usage Instructions
API reference
TCP Sender and Receiver Walkthrough
Sender Walkthrough
After importing Corelink, you first define some constants. You need a server and a certificate that authenticates into that server in order to send data if you are using a self signed certificate on the server side. If you have a certificate that is signed by a trusted certification authority you only need a server without the need to have a certificate. You will also need to set up Corelink username, password, and most importantly importing it.
const config = {
ControlPort: 20012,
/* ControlIP: '127.0.0.1', */
ControlIP: 'corelink.hpc.nyu.edu',
autoReconnect: false,
/*
for service in a local network please replace the certificate with the appropriate version
cert: '<corelink-tools-repo>/config/ca-crt.pem'
*/
}
const username = 'Testuser'
const password = 'Testpassword'
The 3 protocols Corelink currently supports are tcp (TCP), udp (UDP), and ws (Web Socket). Any of the three could be used in the protocol field
In our example we have a random data function to just generate some sample data, so here it is. 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 thesetInterval()
function)
4. Using the Corelink on function to receive call back from receiver, such that the sender will only start sending when at least one receiver is present in the same workspace.
The sender's callback function prevents sending data to an empty workspace. It sets the receiverActive
flag to true
when a valid receiver is present, ensuring data is only sent when it can be received.
const run = async () => {
if (await corelink.connect({ username, password }, config).catch((err) => { console.log(err) })) {
sender = await corelink.createSender({
workspace,
protocol,
type: datatype,
metadata: { name: 'Random Data' },
}).catch((err) => { console.log(err) })
// Provide the sender update callback.
corelink.on('sender', (data) => {
console.log('Sender update:', data)
if (data.receiverID) {
receiverActive = true
} else {
receiverActive = false
}
})
setInterval(async () => {
if (receiverActive && sender) {
const dataToSend = Buffer.from(randomdata());
await corelink.send(sender, dataToSend);
console.log('Data sent:', dataToSend.toString());
}
}, 1000);
}
}
run()
Receiver Walkthrough
After importing Corelink, you first define some constants. You need a server and a certificate that authenticates into that server in order to send data if you are using a self signed certificate on the server side. If you have a certificate that is signed by a trusted certification authority you only need a server without the need to have a certificate. You will also need to set up Corelink username, password, and most importantly importing it.
const config = {
ControlPort: 20012,
/* ControlIP: '127.0.0.1', */
ControlIP: 'corelink.hpc.nyu.edu',
autoReconnect: false,
/*
for service in a local network please replace the certificate with the appropriate version
cert: '<corelink-tools-repo>/config/ca-crt.pem'
*/
}
const username = 'Testuser'
const password = 'Testpassword'
const run = async () => {
if (await corelink.connect({ username, password }, 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()
One sender can send data to multiple receivers, however it can only send one stream, versus a receiver can receive multiple streams at the same time. These streams are by default from multiple senders as each sender can only send one stream.
Source
You can read the code in the examples repository