2012-10-12 4 views
1

Sun RPC를 사용하여 소규모 클라이언트 - 서버 프로그램을 구현하려고합니다. 한 가지 기능은 클라이언트가 모든 형식의 파일을 서버에 업로드 할 수있게하려는 것입니다.Sun RPC를 통해 이진 파일 보내기

는 지금은이 규격이 있습니다

struct add_in{ 
    string author<>; 
    string title<>; 
    opaque file<>; 
}; 

struct node{ 
    struct node * next; 
    int id; 
    string author<>; 
    string title<>; 
    opaque paper<>; 
}; 

struct info_out{ 
    string author<>; 
    string title<>; 
}; 

typedef int add_out; 
typedef int remove_in; 
typedef struct node* list_out; 
typedef int info_in; 
typedef int fetch_in; 
typedef char* fetch_out; 

program FUNCTIONS { 
    version FUNCTIONS_VERS { 
    /* Add function. Adds paper to server "database"*/ 
    add_out ADD_PROC(add_in) = 1; 
    /*Remove function. Removes paper from server "database"*/ 
    void REMOVE_PROC(remove_in) = 2; 
    /*List function. Displays the papers currently stored by the server*/ 
    list_out LIST_PROC() = 3; 
    /*Info function. Displays the auther and title of a specific paper*/ 
    info_out INFO_PROC(info_in) = 4; 
    /*Fetch function. Fetches content of paper from server*/ 
    fetch_out FETCH_PROC(fetch_in) = 5; 
    } = 1; 
} = 0x00000001; 

을이 내 클라이언트입니다 :

#include "functions.h" 
#include <stdio.h> 
#include <stdlib.h> 

char * read_file(char* path){ 
    FILE *file; 
    char *buffer; 
    long file_length; 

    file = fopen(path, "rb"); 
    if(file == NULL){ 
    perror("Unable to open file"); 
    exit(1); 
    } 
    printf("file opened\n"); 

    fseek(file,0,SEEK_END); 
    file_length = ftell(file); 
    fseek(file,0,SEEK_SET); 

    buffer=(char *)malloc(file_length+1); 
    if(buffer == NULL){ 
    perror("Error allocating memory"); 
    exit(1); 
    } 
    printf("Memory allocated\n"); 

    fread(buffer, file_length, 1, file); 
    fclose(file); 

    printf("File imported, fd closed\n"); 
    return buffer; 
} 

int main(int argc, char** argv){ 
    CLIENT *cl; 
    char *buf; 
    add_in in; 
    add_out *out; 

    cl = clnt_create(argv[1], FUNCTIONS, FUNCTIONS_VERS, "tcp"); 
    in.author = argv[3]; 
    in.title = argv[4]; 
    in.file = read_file(argv[5]); 


    out = add_proc_1(&in, cl); 
    if(out == NULL){ 
    fprintf(stderr,"Error: %s\n", clnt_sperror(cl,argv[1])); 
    }else{ 
    printf("%d\n",*out); 
    } 

    return 0; 
} 
문제는 "in.file = read_file (변수는 argv [5])"문에있다

.

호환되지 않는 유형을 유형에서 '구조체'의 char * '

그래서 제 질문은, 그가 포인터 어떤 종류의 필요합니까되어 입력 할당 할 때 : I는 내용의 컴파일러 오류가? ?

감사합니다.

리누스

답변

2

opaque file이 구조체로 번역된다 :

struct { 
    uint file_len; 
    char* file_val; 
} 
관련 문제