Specifications
University of Hertfordshire
38
sin.sin_port = htons(8000); // port equal to 8000 
To bind the new socket to port 8000: 
bind(sock_descriptor, (struct sockaddr *)&sin, sizeof(sin)); 
Finally, the server start listening on the new socket to port 8000: 
listen(sock_descriptor, 20); 
At this point, the server goes into an infinite loop waiting for client’s connection: 
// get a temporary socket to handle client request 
while(1) { 
temp_sock_descriptor = accept(sock_descriptor, (struct sockaddr *)&pin,   
&address_size); 
// receive data from client: 
recv(temp_sock_descriptor, buf, 16384, 0); 
The client’s request must meet some structures, to preset the Spectrum Analyser, the message sent 
by client must equal to “IP”; to identify the Spectrum Analyser’s model, equal to “ID”; to set the 
start frequency, stop frequency, center frequency and span, the data must be in text format, and in 
sequence. 
After received client’s request, the server will control the Spectrum Analyser: 
  // to preset the Spectrum Analyser: 
system ("echo \"SEND 18 \'IP\'\"| cat - > /dev/gpib0"); 
// to identify the Spectrum Analyser’s model 
system ("echo \"SEND 18 \'ID?\'\"| cat - > /dev/gpib0") 
// to set the start frequency, stop frequency, center frequency and span 
system("echo \"SEND  18 \'FA  %s MZ;FB  %s  MZ;CF  %s  MZ;SP  %s  MZ;\'\"|  cat  -> 
/dev/gpib0\n",spec[0],spec[1],spec[2],spec[3]) 
//return result to the client: 
send(temp_sock_descriptor,result[], len,0) 
Chapter Eight: CONCLUSION & FURTHER WORKS 










