As you has seen before The sockets are very useful, but one of the most common problems is transformations data on the network. This transformation data will be use as the representation used by the application and its called as "Presentation Formatting" (Morgan Kaufman,2007).
The STUB
Morgan describe "A stub is the piece of code that implements argument marshalling". the stubs are arguments into a message that can be transmitted by means of the RPC protocol.
Into the server is used to converts message into a set of variables. The variables are used as argument to call the procedure.
The XDR
XDR External Data Representation (XDR) is the network format used with SunRPC. In the taxonomy just introduced, XDR:
- Supports the entire C type system with the exception of function pointers.
- Defines a canonical intermediate form.
- Does not use tags (except to indicate array lengths).
- Uses compiled stubs.
RPC________ Calculadora.x
int arg1;
int arg2;
};
program CALCULADORA {
version CALCULADORA_VER {
int sumar(entrada) = 1;
int restar(entrada) = 2;
int multiplicar(entrada) = 3;
int dividir(entrada) = 4;
} = 1;
} = 0x30000001;
____________________________________
/*
* 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 "calculadora.h"
void
calculadora_1(char *host)
{
CLIENT *clnt;
entrada arg;
arg.arg1=5;
arg.arg2=5;
int *result_1;
int *result_2;
int *result_3;
int *result_4;
#ifndef DEBUG
clnt = clnt_create (host, CALCULADORA, CALCULADORA_VER, "udp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
result_1 = sumar_1(&arg, clnt);
if (result_1 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
result_2 = restar_1(&arg, clnt);
if (result_2 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
result_3 = multiplicar_1(&arg, clnt);
if (result_3 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
result_4 = dividir_1(&arg, clnt);
if (result_4 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
printf(" Suma : %d \n", *result_1);
printf(" Resta : %d \n", *result_2);
printf(" Mult : %d \n", *result_3);
printf(" Div : %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];
calculadora_1 (host);
exit (0);
}
* 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 "calculadora.h"
void
calculadora_1(char *host)
{
CLIENT *clnt;
entrada arg;
arg.arg1=5;
arg.arg2=5;
int *result_1;
int *result_2;
int *result_3;
int *result_4;
#ifndef DEBUG
clnt = clnt_create (host, CALCULADORA, CALCULADORA_VER, "udp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
result_1 = sumar_1(&arg, clnt);
if (result_1 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
result_2 = restar_1(&arg, clnt);
if (result_2 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
result_3 = multiplicar_1(&arg, clnt);
if (result_3 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
result_4 = dividir_1(&arg, clnt);
if (result_4 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
printf(" Suma : %d \n", *result_1);
printf(" Resta : %d \n", *result_2);
printf(" Mult : %d \n", *result_3);
printf(" Div : %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];
calculadora_1 (host);
exit (0);
}
Reference:
Peterson, Larry L.. Computer Networks : A Systems Approach (4th Edition). Burlington, MA, USA: Morgan Kaufmann, 2007. ProQuest ebrary. Web. 14 October 2014.
Copyright © 2007. Morgan Kaufmann. All rights reserved.
No comments:
Post a Comment