Skip to content

Commit

Permalink
init add
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesWang committed Oct 31, 2012
1 parent 4ce23b9 commit 5e9e4b7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
all: client server

hw.h: hw.x
rpcgen hw.x

hw_svc.c hw_clnt.c main.c: hw.h

client: main.o hw_clnt.o
cc -o client main.o hw_clnt.o -lnsl

server: hw_server.o hw_svc.o
cc -o server hw_server.o hw_svc.o -lnsl

.PHONY: clean

clean:
-rm *.o
-rm client
-rm server
-rm hw.h
-rm hw_clnt.c
-rm hw_svc.c
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
HelloWorld-RPC
helloworld-RPC
==============

A VERY simple rpc example to start with.
A VERY simple rpc example to start with.

Reference
=========

* http://people.cs.clemson.edu/~wayne/cpsc824/samples/simple_rpc/index.shtml
* http://www.cs.cf.ac.uk/Dave/C/node34.html
5 changes: 5 additions & 0 deletions hw.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
program HELLO_WOLRD_PROG {
version HELLO_WORLD_VERS {
string HW(void) = 1;
} = 1;
} = 0x30000824;
18 changes: 18 additions & 0 deletions hw_server.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <rpc/rpc.h>
#include "hw.h"

/*
Hello world RPC server -- it just returns the string.
*/

char **hw_1_svc(void *a, struct svc_req *req) {
static char msg[256];
static char *p;

printf("getting ready to return value\n");
strcpy(msg, "Hello world");
p = msg;
printf("Returning...\n");

return(&p);
}
37 changes: 37 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <rpc/rpc.h>
#include "hw.h"

/*
Simple "hello world" program that demonstrates an rpc call.
*/

main (int argc, char *argv[]) {

CLIENT *cl;
char **p;

if (argc != 2) {
printf("Usage: client hostname\n");
exit(1);
}

cl = clnt_create(argv[1], HELLO_WOLRD_PROG, HELLO_WORLD_VERS, "tcp");
if (cl == NULL) {
clnt_pcreateerror(argv[1]);
exit(1);
}

printf("Getting ready to call hello world\n");
p = hw_1(NULL, cl);

printf("Back from hello world\n");
if (p == NULL) {
clnt_perror(cl,argv[1]);
exit(1);
}

printf("Returned string=%s\n", *p);

return 0;
}

0 comments on commit 5e9e4b7

Please sign in to comment.