Home Segments Index Top Previous Next

741: Mainline

At this point, all the socket apparatus is ready to put in place on the client side. The following brings that apparatus together by way of summary:

/* Client Program */ 
#include  
#include  
#include  
#include  
#include  
main ( ) {  
  int socket_number; 
  struct sockaddr_in server_addr; 
  FILE *fm_server, *to_server; 
  server_addr.sin_family = AF_INET; 
  server_addr.sin_port = 6022; 
  server_addr.sin_addr.s_addr = inet_addr ("128.52.36.4"); 
  socket_number = socket (AF_INET, SOCK_STREAM, 0); 
  connect (socket_number, 
           (struct sockaddr *) &server_addr, 
           sizeof (server_addr)); 
  to_server = fdopen (socket_number, "w"); 
  fm_server = fdopen (socket_number, "r"); 
  while (1) { 
    double keyed_number, received_number; 
    printf ("Please type an interest rate:\n> "); 
    scanf ("%lf", &keyed_number); 
    fprintf (to_server, "%f\n", keyed_number); 
    fflush (to_server); 
    fscanf (fm_server, "%lf", &received_number); 
    printf ("Server returned doubling time of %.1f years\n", 
            received_number); 
  } 
}