-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JulesWang
committed
Oct 31, 2012
1 parent
4ce23b9
commit 5e9e4b7
Showing
5 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |