Scripting Only Streaming Solution -> NatNetVersion

NatNet, VRPN, TrackD, and Plugins
Post Reply
Posts: 3
Joined: Thu Oct 02, 2014 1:46 am

Scripting Only Streaming Solution -> NatNetVersion

Post by stefan_s » Mon Oct 06, 2014 7:49 am

Hello everybody,

i am using the arena/motive to unity data stream by directly accessing the data stream, build on the script morgan posted here some time ago. Is there any possibility to access the NatNet Version with this kind of solution? I have seen that the packetclient sample is getting the natnet version by listening to the NAT_PINGRESPONSE message in the command thread. How would i be able to send this ping to natnet and receive its response? So i could make my script solution more stable, handling the different natnet versions correctly.

Thanks so far,

NaturalPoint Employee
NaturalPoint Employee
Posts: 199
Joined: Tue Jun 24, 2008 2:01 pm
Location: Corvallis, OR, USA

Re: Scripting Only Streaming Solution -> NatNetVersion

Post by morgan » Mon Oct 06, 2014 11:46 am

Hi Stefan,

Yes - you can get the NatNet version and Server version using the same mechanism the script uses to get the data descriptions:

1. Instead of sending the NAT_REQUEST_MODELDEF id (4), send the NAT_PING request id (0)

Something like (approximating the original script):

Code: Select all

         Byte[] message = new Byte[100];
         int offset = 0;
         ushort[] val = new ushort[1];
         val[0] = 0; // 0 = NAT_PING
         Buffer.BlockCopy(val, 0, message, offset, 1*sizeof(ushort)); 
         offset += sizeof(ushort);
         val[0] = 0;
         Buffer.BlockCopy(val, 0, message, offset, 1*sizeof(ushort)); 
         offset += sizeof(ushort);
           IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(localIPAddress), commandPort);
         int iBytesSent = sockCommand.SendTo(message, ipep);
         Debug.Log("[UDPClient] sent RequestDescription . (Bytes sent:" + iBytesSent + ")");

2. Parse the command response. Again - some *rough* pseudocode adapting the GetDataDesc section of the original script:

Code: Select all

      if(messageID == 1)      // 1 = Ping Response - From the PacketClient.cpp sample
         strFrame = ("[UDPClient] Read version/server name string");
          // todo : parse natnet server / version - format:
          // char szName[MAX_NAMELENGTH];        // sending app's name
          // unsigned char Version[4];                    // sending app's version []
          // unsigned char NatNetVersion[4];         // sending app's NatNet version []
          Buffer.BlockCopy(b, offset, iData, 0, 4); offset += 4;
          strFrame += String.Format("Dataset Count: {0}\n", iData[0]);
          int nDatasets = iData[0];

The PacketClient.cpp is a working example of how to this - anything you can do in there you should be able to do in the Unity script.

Let us know how it goes.


Post Reply