COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC) 1
2 CONVENTIONAL PROCEDURE CALL (a) (b) Parameter passing in a local procedure call: the stack before the call to read. The stack while the called procedure is active.
3 CLIENT AND SERVER STUBS Principle of RPC between a client and server program.
4 REMOTE PROCEDURE CALLS (1) A remote procedure call occurs in the following steps: 1. The client procedure calls the client stub in the normal way. 2. The client stub builds a message (marshalling the parameters) and calls the local operating system. 3. The client s OS sends the message across the network to the remote OS. 4. The remote OS gives the message to the server stub. 5. The server stub unpacks the parameters 6. Calls the server implementing the function. Continued
5 RPC WITH VALUE PARAMETERS The steps involved in a doing a remote computation through RPC.
6 REMOTE PROCEDURE CALLS (2) A remote procedure call occurs in the following steps (continued): 1. The server does the work and returns the result to the stub. 2. The server stub packs it in a message and calls its local OS. 3. The server s OS sends the message across the network to the client s OS. 4. The client s OS gives the message to the client stub. 5. The stub unpacks the result and returns to the client.
7 PASSING REFERENCE PARAMETERS A pointer is only meaningful in the address space of the process where it is used. One solution is to forbid pointers and reference parameters in RPC More typically, marshalling involves changing the mechanism to copy/restore Actual parameter is sent as a copy If the formal parameter is changed, the changed version is sent back to use as a replacement for the actual Optimizations include taking advantage of the direction of the changes (input only, output only) Straightforward for some parameter types (arrays for example) but not in general.
8 PARAMETER SPECIFICATION AND STUB GENERATION (a) (b) A procedure. The corresponding message. array represented as a pointer is copied in the invocation
COMMUNICATION PROTOCOLS: REMOTE METHOD INVOCATION (RMI) 9
10 RMI RMI = RPC + Object-orientation Java RMI CORBA Middleware that is language-independent Microsoft DCOM/COM+ SOAP RMI on top of HTTP
11 REMOTE AND LOCAL METHOD INVOCATIONS A remote invocation B local C invocation local E invocation local invocation D remote invocation F
12 DISTRIBUTED OBJECTS 2-16 Common organization of a remote object with client-side proxy (loaded when the client binds to a remote object).
13 DISTRIBUTED OBJECTS Remote object references An identifier that can be used throughout a distributed system to refer to a particular remote object Remote interfaces JAVA RMI: Java interface that extends Remote interface Actions: remote invocations Remote Exceptions may arise for reasons such as partial failure or message loss Distributed Garbage Collection: cooperation between local garbage collectors needed
14 RMI PROGRAMMING RMI software Generated by IDL compiler Proxy (client side) Behaves like remote object to clients (invoker) Marshals arguments, forwards message to remote object, unmarshals results, returns results to client Skeleton (server side) Server side stub; Unmarshals arguments, invokes method, marshals results and sends to sending proxy s method Dispatcher (server side) Receives the request message from communication module, passes on the message to the appropriate method in the skeleton
15 RMI PROGRAMMING Binder Client programs need a means of obtaining a remote object reference Binder is a service that maintains a mapping from textual names to remote object references Servers need to register the services they are exporting with the binder Java RMIregistry Server threads Several choices: thread per object, thread per invocation Remote method invocations must allow for concurrent execution
16 JAVA RMI Features Integrated with Java language + libraries Security, write once run anywhere, multithreaded Object orientation Can pass behavior Mobile code Not possible in CORBA, traditional RPC systems Distributed Garbage Collection Remoteness of objects intentionally not transparent
COMMUNICATION PROTOCOLS: SOCKET API 17
18 THE PROGRAMMER'S CONCEPTUAL VIEW OF A TCP/IP INTERNET Application TCP Application UDP IP
19 SOCKET PROGRAMMING Socket API introduced in BSD4.1 UNIX explicitly created, used, released by apps client/server paradigm two types of transport service via socket API: Goal: learn how to build client/server application that communicate using sockets unreliable datagram (UDP) reliable, byte stream-oriented (TCP) socket a host-local, applicationcreated/owned, OS-controlled interface (a door ) into which application process can both send and receive messages to/from another (remote or local) application process
20 SOCKETS AND PORTS socket any port agreed port socket client Internet address = 138.37.94.248 message other ports server Internet address = 138.37.88.249
21 SOCKET PROGRAMMING WITH TCP Client must contact server server process must first be running server must have created socket (door) that welcomes client s contact Client contacts server by: creating client-local TCP socket When client creates socket: client TCP establishes connection to server TCP When contacted by client, server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients specifying IP address, port number of server process application viewpoint TCP provides reliable, in-order transfer of bytes ( pipe ) between client and server
22 CLIENT/SERVER SOCKET INTERACTION: TCP Server (running on hostid) sockfd = socket(af_inet, SOCK_STREAM, 0); bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) Client sockfd = socket(af_inet, SOCK_STREAM, 0); listen(sockfd,5); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); n = read(newsockfd, ); TCP Connection setup connect(sockfd,&serv_addr,sizeof(serv_addr)) n = write(sockfd,buffer,strlen(buffer)); n = write(newsockfd, ); close(newsockfd); n = read(sockfd,buffer,255); close(sockfd);
23 BERKELEY SOCKETS API (1) Socket primitives for TCP/IP. Primitive Socket Bind Listen Accept Connect Send Receive Close Meaning Create a new communication endpoint Attach a local address to a socket Announce willingness to accept connections Block caller until a connection request arrives Actively attempt to establish a connection Send some data over the connection Receive some data over the connection Release the connection
24 BERKELEY SOCKETS (2) Connection-oriented communication pattern using sockets.