Example Code

Previous 

 

Example of telling the server to stream data as 3D coordinates using single precision and then read data from stream:

 

struct HDR_S

  {

  char           cType;

  char           cVersion;

  unsigned int   dwFrameNo;

  short int      nPoints;

  };

 

int nBytesSent = send( socket, "F31\r", 4, 0 );

if ( nBytesSent < 4 )

{

  Error( "Error sending 'F' command to Streaming Server" );

  return FALSE;

}

 

nBytesSent = send( socket, "B\r", 2, 0 );

if ( nBytesSent < 4 )

{

  Error( "Error sending 'B' command to Streaming Server" );

  return FALSE;

}

 

HDR_S  stHdr;

float  fPoints[255][3];

int    nBytesRead;

 

while ( TRUE )

{

  nBytesRead = recv( socket, (char*)&stHdr, sizeof( HDR_S ), 0 );

 

  if ( nBytesRead < sizeof( HDR_S ) ) break;

  if ( ( stHdr.cType != '3' ) || ( stHdr.cVersion != '1' ) ) break;

 

  int nBytesToRead = stHdr.nPoints * ( 3 * sizeof( float ) );

 

  nBytesRead = recv( socket, (char*)&fPoints[0][0], nBytesToRead, 0 );

 

  if ( nBytesRead < nBytesToRead ) break;

 

  // Process the 3D Data Points . . .

  for ( int I = 0; I < stHdr.nPoints; i++ )

  {

     float x = fPoints[i][0];

     float y = fPoints[i][1];

     float z = fPoints[i][2];

 

     DoWhatWeNeedToDoWithThe3DData( x, y, z );

  }

}