主要文件的代码:
fctrl_client_linux.c
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/
#include "fctrl.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void
fctrl_1(char *host)
{
CLIENT *clnt;
int *result_1;
char *rfopen_1_path;
char *rfopen_1_mode;
u_int *result_2;
int rfread_1_handle;
int rfread_1_size;
char *rfread_1_buff;
u_int *result_3;
int rfwrite_1_handle;
int rfwrite_1_size;
char *rfwrite_1_buff;
int *result_4;
int rfclose_1_handle;
int *result_5;
int rfseek_1_handle;
long rfseek_1_offset;
int rfseek_1_init_pos;
clnt = clnt_create (host, FCTRL, VERSION, "udp");
if (clnt == NULL)
{
clnt_pcreateerror (host);
exit (1);
}
//----------
rfopen_1_path = "test.txt";
rfopen_1_mode = "w+";
result_1 = rfopen_1(rfopen_1_path, rfopen_1_mode, clnt);
if (result_1 == (int *) NULL)
{
clnt_perror (clnt, "call failed");
}
int handle = *result_1;
printf("rfopen result: %d/n", handle);
//----------
rfwrite_1_handle = handle;
rfwrite_1_buff = "This is a test. /n /
This line will be write into remote file.";
rfwrite_1_size = strlen(rfwrite_1_buff);
result_3 = rfwrite_1(rfwrite_1_handle, rfwrite_1_size, rfwrite_1_buff, clnt);
if (result_3 == (u_int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfwrite result: %d/n", *result_3);
//---------
result_5 = rfseek_1(handle, 0, SEEK_SET, clnt);
if (result_5 == (int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfseek result: %d/n", *result_5);
//---------
struct read_ret * res;
res = rfread_1(handle, 1024, clnt);
if (result_2 == (u_int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfread result: [%d]/n%s/n", res->count, res->str);
result_4 = rfclose_1(handle, clnt);
if (result_4 == (int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfclose result: %d/n", *result_4);
clnt_destroy (clnt);
}
int
main (int argc, char *argv[])
{
char *host;
if (argc < 2) {
printf ("usage: %s server_host/n", argv[0]);
exit (1);
}
host = argv[1];
fctrl_1 (host);
exit (0);
}
fctrl_client_windows.c
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/
#include "fctrl.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#pragma comment(lib, "D32-RPC.LIB")
void
fctrl_1(char *host)
{
HCLIENT *clnt;
int *result_1;
u_int *result_2;
int rfread_1_handle;
int rfread_1_size;
char *rfread_1_buff;
u_int *result_3;
int rfwrite_1_handle;
int rfwrite_1_size;
char *rfwrite_1_buff;
int *result_4;
int rfclose_1_handle;
int *result_5;
int rfseek_1_handle;
long rfseek_1_offset;
int rfseek_1_init_pos;
char * rfopen_1_path;
char * rfopen_1_mode;
int file_handle;
long offset;
int init_pos;
struct read_ret * res;
int read_count = 1024;
clnt = clnt_create (host, FCTRL, VERSION, "udp");
if (clnt == NULL)
{
// clnt_geterror (host);
exit (1);
}
//----------
rfopen_1_path = "test.txt";
rfopen_1_mode = "w+";
result_1 = rfopen_1(&rfopen_1_path, &rfopen_1_mode, clnt);
if (result_1 == (int *) NULL)
{
clnt_perror (clnt, "call failed");
}
file_handle = * result_1;
printf("rfopen result: %d/n", file_handle);
//----------
rfwrite_1_handle = file_handle;
rfwrite_1_buff = "This is a test. /n /
This line will be write into remote file.";
rfwrite_1_size = strlen(rfwrite_1_buff);
result_3 = rfwrite_1(&rfwrite_1_handle, &rfwrite_1_size, &rfwrite_1_buff, clnt);
if (result_3 == (u_int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfwrite result: %d/n", *result_3);
//---------
offset = 0;
init_pos = SEEK_SET;
result_5 = rfseek_1(&file_handle, &offset, &init_pos, clnt);
if (result_5 == (int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfseek result: %d/n", *result_5);
//---------
read_count = 1024;
res = rfread_1(&file_handle, &read_count, clnt);
if (result_2 == (u_int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfread result: [%d]/n%s/n", res->count, res->str);
result_4 = rfclose_1(&file_handle, clnt);
if (result_4 == (int *) NULL)
{
clnt_perror (clnt, "call failed");
}
printf("rfclose result: %d/n", *result_4);
}
int
main (int argc, char *argv[])
{
char *host;
if (argc < 2) {
printf ("usage: %s server_host/n", argv[0]);
exit (1);
}
host = argv[1];
fctrl_1 (host);
return 0;
}
fctrl_server.c
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/
#include "fctrl.h"
#include <stdio.h>
int *
rfopen_1_svc(char *path, char *mode, struct svc_req *rqstp)
{
static int result;
printf("Client Call Procdure: rfopen(%s, %s)/n", path, mode);
FILE * file = fopen(path, mode);
if (file == NULL)
{
printf("fopen failed!");
}
result = (int) file;
printf("Call Successed!: rfopen(%s, %s) = %d/n", path, mode, result);
return &result;
}
read_ret *
rfread_1_svc(int handle, int size, struct svc_req *rqstp)
{
static read_ret result;
printf("Client Call Procdure: rfread(%d, %d)/n", handle, size);
FILE * file = (FILE *) handle;
result.str = (char *)malloc(sizeof(char) * size);
memset(result.str, 0, size);
result.count = fread(result.str, sizeof(char), size, file);
printf("Call Successed!: rfread() = %d/n%s", result.count, result.str);
return &result;
}
u_int *
rfwrite_1_svc(int handle, int size, char *buff, struct svc_req *rqstp)
{
static u_int result;
printf("Client Call Procdure: rfwrite(%d, %d, %s)/n", handle, size, buff);
FILE * file = (FILE *) handle;
result = fwrite(buff, sizeof(char), size, file);
printf("Call Successed!: rfwrite() = %d/n", result);
return &result;
}
int *
rfclose_1_svc(int handle, struct svc_req *rqstp)
{
static int result;
printf("Client Call Procdure: rfclose(%d)/n", handle);
FILE * file = (FILE *) handle;
result = fclose(file);
printf("Call Successed!: rfclose() = %d/n", result);
return &result;
}
int *
rfseek_1_svc(int handle, long offset, int init_pos, struct svc_req *rqstp)
{
static int result;
printf("Client Call Procdure: rfseek(%d, %ld, %d)/n", handle, offset, init_pos);
FILE * file = (FILE *) handle;
result = fseek(file, offset, init_pos);
printf("Call Successed!: rfseek() = %d/n", result);
return &result;
}
心得体会: