#include #include #include #include #include #include #include #include #include #include #include int make_connection(int, char*); main(int argc, char *argv[]) { char machine[100]; int port; float factor1; float factor2; float product; int connection; int i; int descriptor; /*****************************************************************/ /* Check command line Arguments - Notice there are five */ if(argc != 5) { printf("Usage: my_client -p # -m sss#\n"); printf(" where -p # is port number\n"); printf(" where -m sss is machine name\n"); exit(0); } for( i = 0; i < 5; i++) { if( !strcmp(*(argv + i), "-p")) { port = (int) atoi( *(argv+i+1)); } if( !strcmp(*(argv + i), "-m")) { strcpy(machine, *(argv+i+1)); } } descriptor = make_connection( port, machine ); if(!descriptor) { printf("connect failure\n"); exit(0); } printf("You have a connection to %s on port %d\n", machine, port); /*****************************************************************/ connection = 1; while(connection != 0) { printf("To disconnect, type 0, to continue, type 1\n"); scanf("%d", &connection); i = write(descriptor, (char *) &connection, sizeof(int)); printf("I have just WRITTEN %d bytes representing %d\n",i,connection); if(connection != 0 ) { printf("type the first number\n"); scanf("%f",&factor1); printf("type the second number\n"); scanf("%f",&factor2); i = write(descriptor, (char *) &factor1, sizeof(float)); printf("I have just WRITTEN %d bytes representing %f\n",i,factor1); i = write(descriptor, (char *) &factor2, sizeof(float)); printf("I have just WRITTEN %d bytes representing %f\n",i,factor2); i = read(descriptor, (char *) &product, sizeof(float)); printf("I have just read %d bytes representing THE PRODUCT %f\n",i,product); } } close(descriptor); printf("Bye...\n"); }