Professional Documents
Culture Documents
Tim Salo
Execute
% ./RPCdemo
} = 1; Define function
} = 0x20004088;
#include <rpc/rpc.h>
#ifdef __cplusplus
extern "C" {
#endif
struct add_1_argument {
int arg1;
int arg2;
};
typedef struct add_1_argument add_1_argument;
...
RPCdemo_clnt.c
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
int *
add_1(int arg1, int arg2, CLIENT *clnt)
{
add_1_argument arg;
static int clnt_res;
...
RPCdemo_svc.c
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "RPCdemo.h"
#include <stdio.h>
#include <stdlib.h>
#include <rpc/pmap_clnt.h>
#include <string.h>
#include <memory.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifndef SIG_PF
#define SIG_PF void(*)(int)
#endif
...
RPCdemo_xdr.c
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "RPCdemo.h"
bool_t
xdr_add_1_argument (XDR *xdrs, add_1_argument *objp)
{
if (!xdr_int (xdrs, &objp->arg1))
return FALSE;
if (!xdr_int (xdrs, &objp->arg2))
return FALSE;
return TRUE;
}
RPCdemo_server.c (part 1 of 2)
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use
them
* as a guideline for developing your own
functions.
*/
RPCdemo_server.c (part 2 of 2)
#include "RPCdemo.h"
return &result;
}
RPCdemo_client.c (part 1 of 3)
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use
them
* as a guideline for developing your own
functions.
*/
RPCdemo_client.c (part 2 of 3)
#include "RPCdemo.h"
return &result;
}
Run It! (Version 2)
lind24-06% RPCdemo_server
lind24-06% RPCdemo_server
add(1, 2) called.
Review – All We Did Was...
Create RPCdemo.x
program RPCDEMO {
version RPCDEMOVERS {
} = 1;
} = 0x20004088;
Run rpcgen.
Review – All We Did Was...
Modify skeleton server code
return &result;
}
Review – All We Did Was...
Modify skeleton client code.
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public Server() {}
try {
Server obj = new Server();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
Client ( 1 of 2)
package example.hello;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
private Client() {}
•Start Registry
Client:
% java -classpath classDir
example.hello.Client
Output:
response: Hello, world!
Concluding Thoughts and Hints
• Why use Sun RPC
– It’s simple
– Its transparent
» You can look at it and see how it works
• But
– It gives the C/Unix error message
» segmentation fault
– It performs C/Unix error checking
» none
» Real programmers don’t make mistakes
Concluding Thoughts and Hints
• So
– Be patient
– Be methodical
– Don’t be too aggressive (maybe)
– Don’t be too tricky
– Develop incrementally
– Save working versions
Concluding Thoughts and Hints
• And
– Use the IT Labs machines
» There are a lot of them
» You can (usually) ssh in
» You won’t fight with firewalls, SELinux
• Careful
– Sun RPC is not reentrant
» Static variables
– Interaction with threads can be messy
Concluding Thoughts and Hints
• Documentation
– man rpc
– man rpcgen
– Sun ONC+ Documentation
– I will update the RPC and RMI resources on
the class Web pages
Concluding Thoughts and Hints
Questions