Remote Procedure Calls: Network Transfer Protocols
Remote Procedure Calls: Network Transfer Protocols
Adapted from:
Paul Krzyzanowski
[email protected]
[email protected]
Except as otherwise noted, the content of this presentation is licensed under the Creative Commons
Attribution 2.5 License.
Page 1
Connection Oriented
• often reliable, stream based
• analogous to making a direct phone call
• TCP (Transmission Control Protocol) is a connection-based
protocol that provides a reliable flow of data between two
computers
Connectionless
• unreliable, datagram based
• analogous to sending letters via the postal service
• UDP (User Datagram Protocol) is a protocol that sends
independent packets of data, called datagrams, from one
computer to another with no guarantees about arrival. UDP is
not connection-based like TCP.
Page 2
Internet Protocol and the TCP/IP Protocol Suite
Host A Host B
Client Server
Network
TCP IP Driver Driver IP TCP
Page 3
Sockets
• Sockets ( Berkley sockets) are one of the most widely used communication APIs.
• A socket is an object from which messages and are sent and received.
• A socket is a network communication endpoint.
• In connection-based communication such as TCP, a server application binds a socket to a
specific port number. This has the effect of registering the server with the system to receive all
data destined for that port. A client can then rendezvous with the server at the server's port, as
illustrated here:
• Data transfer operations on sockets work just like read and write operations on files. A socket is
closed, just like a file, when communications is finished.
• Network communications are conducted through a pair of cooperating sockets, each known as
the peer of the other.
• Processes connected by sockets can be on different computers (known as a heterogenous
environment) that may use different data representations.
• Data is serialized into a sequence of bytes by the local sender and deserialized into a local data
format at the receiving end.
Page 4
Problems with sockets
Page 5
RPC
Page 6
Regular procedure calls
Page 7
You write:
x = f(a, “test”, 5);
Page 8
Implementing RPC
Page 9
Implementing RPC
The trick:
Page 10
Remote Procedue Calls
Page 11
Page 12
Marshalling and Unmarshalling
• Marshalling: Disassemble
(encode) data structures into
transmittable form
• Unmarshalling: Reassemble
(decode) transmitted form into
original complex data structure.
Page 13
Caller
Caller Called
Called
Caller
Stub
Stub
Stub
Called
Called
Transport
TransportLayer
Layer (e.g.
(e.g.TCP
TCP or
or UDP)
UDP)
Page 14
Stubs
Page 15
Stub functions
server stub
client stub
(skeleton)
client server
Page 16
Stub functions
server stub
client stub
(skeleton)
client server
Page 17
Stub functions
server stub
client stub
(skeleton)
client server
Page 18
Stub functions
server stub
client stub
(skeleton)
client server
Page 19
Stub functions
server stub
client stub
(skeleton)
client server
Page 20
Stub functions
server stub
client stub
(skeleton)
client server
Page 21
Stub functions
server stub
client stub
(skeleton)
client server
Page 22
Stub functions
server stub
client stub
(skeleton)
client server
Page 23
Stub functions
server stub
client stub
(skeleton)
client server
Page 24
Stub functions
server stub
client stub
(skeleton)
client server
Page 25
Benefits
Page 26
RPC has issues
Page 27
Parameter passing
Pass by value
– Easy: just copy data to network message
Pass by reference
– Makes no sense without shared memory
Page 28
Pass by reference?
Page 29
Representing data
No such thing as
incompatibility problems on local system
Page 30
Where to bind?
Page 31
Transport protocol
Which one?
Page 32
When things go wrong
Page 33
Page 34
RPC semantics
• Understand application:
– idempotent functions: may be run any number of
times without harm
– non-idempotent functions: side-effects
Page 35
More issues
Performance
– RPC is slower … a lot slower
Security
– messages visible over network
– Authenticate client
– Authenticate server
Page 36
Programming with RPC
Language support
– Most programming languages (C, C++, Java, …) have
no concept of remote procedure calls
– Language compilers will not generate client and
server stubs
Common solution:
– Use a separate compiler to generate stubs (pre-
compiler)
Page 37
Page 38
RPC compiler
client
client code
code (main)
(main)
client
client stub
stub
data
data conv.
conv. compiler
compiler client
client
RPC
RPC
IDL
IDL compiler
headers
headers
compiler
data
data conv.
conv. compiler
compiler server
server
server
server skeleton
skeleton
server
server functions
functions
Code you write
Server functions
– Generally need little or no modification
Page 40
RPC API
• Binding operations
– Establish client/server communications using
appropriate protocol (establish endpoints)
• Endpoint operations
– Listen for requests, export endpoint to name server
Page 41
RPC API
• Security operations
– Authenticate client/server
• Internationalization operations
• Marshaling/data conversion operations
• Stub memory management
– Dealing with “reference” data, temporary buffers
• Program ID operations
– Allow applications to access IDs of RPC interfaces
Page 42