Remote Procedure Calls (RPC)

Similar documents
Networks and Protocols Course: International University Bremen Date: Dr. Jürgen Schönwälder Deadline:

Category: Standards Track August 1995

Sources: On the Web: Slides will be available on:

Illustration 1: Diagram of program function and data flow

Getting Started with the Internet Communications Engine

Introduction to Socket programming using C

SQLITE C/C++ TUTORIAL

Informatica e Sistemi in Tempo Reale

Moving from CS 61A Scheme to CS 61B Java

Elementary Name and Address. Conversions

CORBA Programming with TAOX11. The C++11 CORBA Implementation

MCP/AS. ONC+ Remote Procedure Call (RPC) for MCP/AS Installation and Programming Guide MCP 12.0

Java Program Coding Standards Programming for Information Technology

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

/* File: blkcopy.c. size_t n

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Tutorial on C Language Programming

CSC230 Getting Starting in C. Tyler Bletsch

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents

The C Programming Language course syllabus associate level

1 Abstract Data Types Information Hiding

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

Apache Thrift and Ruby

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

MatrixSSL Porting Guide

An Incomplete C++ Primer. University of Wyoming MA 5310

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

System Calls and Standard I/O

Simple C Programs. Goals for this Lecture. Help you learn about:

Lab 4: Socket Programming: netcat part

Netscape Internet Service Broker for C++ Programmer's Guide. Contents

C++ Programming Language

An Overview of Java. overview-1

Project 2: Bejeweled

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Specific Simple Network Management Tools

Sensors and the Zaurus S Hardware

Last Class: Communication in Distributed Systems. Today: Remote Procedure Calls

Lecture 17. Process Management. Process Management. Process Management. Inter-Process Communication. Inter-Process Communication

Tail call elimination. Michel Schinz

File Handling. What is a file?

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

El Dorado Union High School District Educational Services

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Lesson 4 Web Service Interface Definition (Part I)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

CSE 333 SECTION 6. Networking and sockets

MPLAB Harmony System Service Libraries Help

Shared file. LINUX Virtual File System. Hard link. Linux ext2fs. Disk layout in general. Linux: ext2fs & ext3fs, Windows NTFS Distributed Processing

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Virtuozzo Virtualization SDK

Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG

Keil C51 Cross Compiler

Pemrograman Dasar. Basic Elements Of Java

Hands-on Hacking Unlimited

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

Objective-C Tutorial

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Introduction to Java

TFTP Usage and Design. Diskless Workstation Booting 1. TFTP Usage and Design (cont.) CSCE 515: Computer Network Programming TFTP + Errors

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Distributed Network Management Using SNMP, Java, WWW and CORBA

As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

Distributed Internet Applications - DIA. Principles of Object-Oriented Middleware

Grundlagen der Betriebssystemprogrammierung

What is COM/DCOM. Distributed Object Systems 4 COM/DCOM. COM vs Corba 1. COM vs. Corba 2. Multiple inheritance vs multiple interfaces

Embedded Software Development

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions


Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

7th Marathon of Parallel Programming WSCAD-SSC/SBAC-PAD-2012

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

Brent A. Perdue. July 15, 2009

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Libmonitor: A Tool for First-Party Monitoring

Device Management API for Windows* and Linux* Operating Systems

The programming language C. sws1 1

Chapter 13 Storage classes

How to Add a New System Call for Minix 3

Chapter 1 Java Program Design and Development

Chapter 2 Introduction to Java programming

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

CSCE 665: Lab Basics. Virtual Machine. Guofei Gu

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

sys socketcall: Network systems calls on Linux

Module 816. File Management in C. M. Campbell 1993 Deakin University

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Chapter 2: Remote Procedure Call (RPC)

InterBase 6. Embedded SQL Guide. Borland/INPRISE. 100 Enterprise Way, Scotts Valley, CA

J a v a Quiz (Unit 3, Test 0 Practice)

C++FA 5.1 PRACTICE MID-TERM EXAM

Logging. Working with the POCO logging framework.

Infrastructure that supports (distributed) componentbased application development

C Interview Questions

C++ INTERVIEW QUESTIONS

Transcription:

Remote Procedure Calls (RPC) 1 Remote Procedure Call Remote procedures appear local through stub functions Stub functions have the same functional interface Communicate with server Await results from server 2

Stub Function Generation Programming languages do not support Sun RPC A separate pre-compiler, rpcgen, must be used Input: Interface definition language Output: Server main routine Client stub functions Header file Data conversion functions, if needed Makefile 3 Interface Definition Language Used by rpcgen to generate stub functions Defines an RPC program: collection of RPC procedures Structure: 4

Data Types Constants May be used in place of an integer value - converted to #define statement by rpcgen const MAXSIZE = 512; Structures Similar to C structures - rpcgen transfers structure definitions and adds a typedef for the name of the structure struct intpair { int a, b ; is translated to: struct intpair { int a, b ; typedef struct intpair intpair; 5 Data Types Enumerations Similar to C enum state { BUSY=1, IDLE=2, TRANSIT=3 ; Unions Not like C A union is a specification of data types based on some criteria: union identifier switch (declaration) { case_list For example: const MAXBUF=30; union time_results switch (int status) { case 0: char timeval[maxbuf]; case 1: void; case 2: int reason; 6

Data Types Type definitions Like C: typedef long counter; Arrays Like C but may have a fixed or variable length: int proc_hits[100]; defines a fixed size array of 100 integers. long x_vals<50> defines a variable-size array of a maximum of 50 longs Pointers Like C, but not sent over the network. What is sent is a Boolean value (true for pointer, false for null) followed by the data to which the pointer points 7 Data Types Strings Declared as if they were variable length arrays string name<50>; Declares a string of at most 50 characters. string anyname<>; Declares a string of any number of characters. Boolean Can have the value of TRUE or FALSE: bool busy; Opaque data Untyped data that contains an arbitrary sequence of bytes - may be fixed or variable length: opaque extra_bytes[512]; opaque more<512>; Latter definition is translated to C as: struct { uint more_len; /* length of array */ char *more_val; /* space used by array */ 8

Using rpcgen rpcgen has the following options that are nice: a generate all the files including sample code for the server and client C generate ANSI C code. This should be used if you are using the C++ compiler N use the new style of rpcgen. This allows procedures to have multiple arguments. It also uses the style of parameter passing that closely resembles C 9 Writing Functions using RPC Create a procedure whose name is the name of the RPC definition In lowercase Followed by an underscore, version number, underscore, svc For example, BLIP blip_1_svc Argument to procedure is a pointer to the argument data type specified in the IDL Default behavior: only one parameter to each function If you want more, use a struct This was relaxed in later versions of rpcgen but remains the default Procedure must return a pointer to the data type specified in the IDL The server stub uses the procedure s return value after the procedure returns, so the return address must be that of a static variable 10

Sample RPC Program Start with stand-alone program that has two functions: bin_date returns system date as # seconds since Jan 1 1970 0:00 GMT str_date takes the number of seconds as input and returns a formatted data string Goal Move bin_date and str_date into server functions and call them via RPC. 11 Stand-alone Program #include <stdio.h> long bin_date(void); char *str_date(long bintime); int main(int argc, char **argv) { long lresult; /* return from bin_date */ char *sresult; /* return from str_date */ if ( argc!= 1 ) { fprintf(stderr, "usage: %s\n", argv[0]); exit(1); /* call the procedure bin_date */ lresult = bin_date(); printf( "time is %ld\n", lresult ); /* convert the result to a date string */ sresult = str_date(lresult); printf( "date is %s", sresult ); /* main */ 12

Stand-alone Program: Functions /* bin_date returns the system time in binary format */ long bin_date( void ) { long timeval; long time(); /* Unix time function; returns time */ timeval = time( (long *)0 ); return timeval; /* bin_date */ /* str_date converts a binary time into a date string */ char *str_date( long bintime ) { char *ptr; char *ctime(); /* Unix library function that does the work */ ptr = ctime( &bintime ); return ptr; /* str_date */ 13 Define Remote Interface (IDL) Define two functions that run on server: bin_date has no input parameters and returns a long str_date accepts a long as input and returns a string IDL: program DATE_PROG { version DATE_VERS { long BIN_DATE(void) = 1; string STR_DATE(long) = 2; = 1; = 55; Version number Program number IDL convention is to suffix the file with.x We name the file date.x It can be compiled with: rpcgen -C N a date.x Function numbers 14

date_server.c #include date.h long * bin_date_1_svc( struct svc_req *rqstp ) { static long result; /* insert server code here */ return &result; char ** str_date_1_svc( long arg1, struct svc_req *rqstp ) { static char *result; /* insert server code here */ return &result; 15 Fixing date_server.c Now just copy the functions from the original stand-alone code long * bin_date_1_svc( struct svc_req *rqstp ) { static long result; result = time( (long *)0 ); return &result; char ** str_date_1_svc( long arg1, struct svc_req *rqstp ) { static char *result; result = ctime( &arg1 ); return &result; 16

Fixing data_client.c We need to know the name of the server Use getopt library function to accept a -h hostname argument on the command line. The following is placed in the main function of date_client.c char *host = "localhost"; /* default */ char c; int err = 0; while ( ( c = getopt( argc, argv, "h:" ) )!= -1 ) switch ( c ) { case 'h': server = optarg; break; case '?': err = 1; break; /* switch */ /* exit if error or extra arguments */ if ( err ( optind < argc ) ) { fprintf( stderr, "usage: %s [-h hostname]\n", argv[0] ); exit(1); /* if */ 17 Fixing date_client.c (cont) Before we can make any remote procedure calls, we need change the last parameter from udp to tcp: cl = clnt_create(server, DATE_PROG, DATE_VERS, tcp ); Program and version numbers are defined in date.h. tcp directs to transport using TCP. The server s RPC name server (port mapper) is contacted to find the port for the requested program/version/transport. Remember, you may have to start or stop the port mapper /etc/init.d/portmap start /etc/init.d/portmap stop 18

Fixing date_client.c (cont) Fix the call to str_date to take the result from bin_date Change To result_2 = str_date_1( str_date_1_arg1, clnt); result_2 = str_date_1( *result_1, clnt); 19 Fixing date_client.c (cont) If the call to bin_date_1 succeeds, print the result: printf( Time on %s is %ld\n server, *result_1); If the call to str_date_1 succeeds, print the result: printf( Date is %s, *result_2 ); 20

Compile Link Run Generate the stubs rpcgen a N C date.x Compile and link the client code gcc g c date_clnt.c gcc g c date_client.c gcc g o date_client date_clnt.o date_client.o -lnsl Compile and link the server code gcc g c date_svc.c gcc g c date_server.c gcc g o date_server date_svc.o date_server.o -lnsl Run the server $./date_server Run the client $./date_client h kiev.cs.usu.edu Time on localhost is 1067637751 Date is Fri Oct 31 15:02:31 2003 21