2

I am using Sun XDR RPC in ubuntu 14. I need to send and receive an image over RPC for compression. Here is my .x file

onst MAXPARAMNAME = 9024;
typedef string prog<MAXPARAMNAME>;
struct prognames
{
 prog program1;
 int index;

};

program RPC_PROG {                                               
    version RPC_VERS {                                         
 string RUN_PROGS(prognames) = 1; /* procedure numer=1 */
    } = 1; /* version number = 1 */

} = 0x12345678; /* program number = 0x12345678 */

Following is client file

FILE *imageN=fopen("index.jpg", "r");
   char b[9024];
    int i=0;
   while(!feof(imageN))
   {
          fread(b, 1,1024,imageN );

          i+=1024;
          fseek( imageN,i, SEEK_SET );

}

   prognames args;
   args.program1 =&b;


   /*remote procedure run_progs */
   resultStringFromServerExecutePrograms = run_progs_1(&args, cl);

I am only mentioning that code where image is being sent. Finally server code:

char** run_progs_1_svc(prognames *argparams, struct svc_req *arg2)
{
 FILE* fpipe;

 char* program1AndProgram2;
 char* prog1 = argparams->program1;
static char* readPipeInto1;
 readPipeInto1 = (char*)malloc((READ_MAX_SIZE + 1)*sizeof(char));
 static char* readPipeInto;
 readPipeInto = (char*)malloc((READ_MAX_SIZE + 1)*sizeof(char));
 memset(readPipeInto, 0, READ_MAX_SIZE + 1);
 program1AndProgram2=(char*)malloc((strlen(prog1))*sizeof(char));
 strcpy(program1AndProgram2, argparams->program1);

 //execute commands
 if ( !(fpipe= (FILE*)fopen("tst.jpg","w")) )
 { 
   perror("Cant open pipe!");
   exit(1);
 }
 fwrite(program1AndProgram2,0,8024,fpipe);
 long length;
 //calculating size of file

 //fread((char *)readPipeInto1, length, 1, fpipe); 
 fclose(fpipe); 
 //compression code

After running code, server side says that the file is empty. While on the client side after a while following error is generated.

localhost: RPC: Unable to receive; errno = Connection refused

Basic logic behind my code is that client reads from file stores it in the structure and then sends this structure to server (RPC). Server writes data in structure to a file and then opens that file and compresses. But I'm not sure whether my logic is correct or not.

cranberry
  • 55
  • 7

0 Answers0