1

I am using the OSC module https://github.com/colinbdclark/osc.js but I am struggling to get it to work over TCP. I am unable to find any examples that use TCP, they are all based on UDP.

I have tried just creating a TCP client in node.js but still struggle to get the message encoded correctly into OSC format. I also believe it has to be encoded with SLIP as well?

I am very new at this so be gentle.

Would be amazing if someone could please point me in the right direction or provide an example about sending OSC messages via TCP in node.js

Thank you!

Wayde

PS. Happy to use osc-min module as well. As I know with that you can encode the message to an osc message and store in a var. But still can't get it to work over TCP .. works fine over UDP but my replys are larger than the what UDP can handle if that makes sense

Wayde
  • 53
  • 7

1 Answers1

3

I'm not very familiar with OSC, so I don't know about its internals, but osc.js does support TCP transport, like this:

let server = new osc.TCPSocketPort({});

server.open('127.0.0.1', 57121); // change to remote host/port

server.on('ready', () => {
  console.log('ready');
  ...
});

According to the README:

For stream-based protocols such as serial and TCP, osc.js will take care of SLIP framing for you.

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • Thanks so much. Currently on a train and laptop is flat. But I will try later on tonight. I couldn't find an example of how to use it via TCP but judging by yours, I was getting closer ;) will let you know asap. – Wayde Mar 09 '17 at 18:52
  • amazing! works one i changed it from server as that is already defined...now i get the replies using - let tcpServer = new osc.TCPSocketPort({}); tcpServer.open('127.0.0.1', 53000); tcpServer.send({ address: "/version", args: 1, }, '127.0.0.1', 53000); tcpServer.on('data', function(data) { console.log('DATA: ' + data); }); But the reply in console isn't quite the same as a UDP message �/reply/version,s{"status":"ok","address":"\/version","data":"4.0.6"}� Normally I would access this via data.status to get status value. – Wayde Mar 09 '17 at 20:48
  • @Wayde I don't have an OSC server to test against, but it looks like you're getting the raw packet data there. Because of the SLIP framing, it might be that you need to unpack the data first. Instead of listening for the `data` event, try listening for the `message` event (FWIW, I'm piecing all this together from the [`osc.js`](https://github.com/colinbdclark/osc.js) source and [it's example repository](https://github.com/colinbdclark/osc.js-examples)). – robertklep Mar 10 '17 at 06:00
  • of course, i used the same method as the working UDP replies tcpServer.on('message', function(oscBundle, timeTag, info) { console.log('Message: ' + oscBundle.args); }); Thank you very much for your help!! – Wayde Mar 11 '17 at 12:36