/*An application program on the client side,it access functions sum and product as if they were local. */ #include <stdio.h> #include "service.h" char dispatcher[100]; /*to contain the ip address of dispatcher*/ int port; /*to contain the port number of dispatcher*/ int main(int argc, char **argv) { int status=0; int a,b,c; int func; char op[10]; char garbage[30]; /*just used for format.*/ if(argc<3) { fprintf(stderr,"Wrong command line arguements!\n"); exit(-1); } strcpy(dispatcher,argv[1]);/*get the ip address of disptcher*/ port=atoi(argv[2]);/*get the port number of dispatcher.*/ /*a user friendly interface.*/ while(1) { printf("\nPlease select the function:\n"); printf("0.sum\t1.product\n"); func=getchar(); /*read the function selected from stdin*/ fgets(garbage,sizeof(garbage),stdin); /*just for format*/ /*if user press any chars other than '0' or '1'*/ if(func!='0'&&func!='1') { printf("Invalid option, select again\n"); continue; } printf("Please input the operand:\n"); printf("a = "); scanf("%d",&a); fflush(stdout); printf("b = "); scanf("%d",&b); fflush(stdout); /*the case sum function is selected.*/ if(func=='0') { status=sum(a,b,&c); strcpy(op,"+"); break; } /*the case product operation is selected*/ else if(func=='1') { status=product(a,b,&c); strcpy(op,"*"); break; } printf("\n"); } /*if nothing wrong happened.*/ if(status==0) printf("\n%d %s %d = %d \n\n",a,op,b, c); return 0; }