Agilent Technologies E4406A VSA Satellite Radio User Manual


 
158 Chapter 3
Programming Examples
Using C Programming Over Socket LAN
count = recv(sock, tmp_buf, 1, 0); /* read 1 char */
ch = tmp_buf[0];
if ((count < 1) || (ch == EOF) || (ch == \n))
{
*result = \0; /* null terminate result for ascii */
return 0;
}
/* use a do-while so we can break out */
do
{
if (ch == #)
{
/* binary data encountered - figure out what it is */
long numDigits;
long numBytes = 0;
/* char length[10]; */
count = recv(sock, tmp_buf, 1, 0); /* read 1 char */
ch = tmp_buf[0];
if ((count < 1) || (ch == EOF)) break; /* End of file */
if (ch < 0 || ch > 9) break; /* unexpected char */
numDigits = ch - 0;
if (numDigits)
{
/* read numDigits bytes into result string. */
count = recv(sock, result, (int)numDigits, 0);
result[count] = 0; /* null terminate */
numBytes = atol(result);
}
if (numBytes)
{