Transcript chapterw5i

Chapter 4: Interprocess Communication
•
•
•
•
•
•
Introduction
The API for the Internet protocols
External data representation and marshalling
Client-Server communication
Group communication
Case study: interprocess communication in Java
1
Introduction
• Internet and WWW have emerged as global
media for communication and changing the
way we conduct science, engineering, and
commerce.
• They also changing the way we learn, live,
enjoy, communicate, interact, engage, etc. It
appears like the modern life activities are
getting completely centered around the
Internet.
2
Internet Applications Serving Local and
Remote Users
PC client
Internet
Server
Local Area Network
PDA
3
The characteristics of interprocess communication
• Synchronous and asynchronous
– a queue associated with message destination, Sending process add
message to remote queue, Receiving process remove message from local
queue
– Synchronous: send and receive are blocking operations
– asynchronous: send is unblocking, receive could be blocking or
unblocking (receive notification by polling or interrupt)
• Message destination
– Internet address + local port
– service name: help by name service at run time
– location independent identifiers, e.g. in Mach
• Reliability
– validity: messages are guaranteed to be delivered despite a reasonable
number of packets being dropped or lost
– Integrity: messages arrive uncorrupted and without duplication
• Ordering
– the messages be delivered in sender order
4
Process p
Process q
send m
receive
Message
(sequence of bytes)
Communication channel
Outgoing message buffer
• A communication channel can be
described in terms of four
attributes
• Performance – dictated by the
network latency and bandwidth
• Reliability
– Validity - a message put in the
outgoing buffer is eventually
delivered to the incoming
message buffer
– Integrity – the message received
is identical to the one sent, and
no messages are delivered twice
Incoming message buffer
• Ordering
– A channel is ordered if messages
are delivered in the order in
which they were sent
• Synchronicity
– Synchronous – each message
transmitted over a channel is
received within a known
bounded time
– Asynchronous – message
transmission time is unbounded
5
The Internet protocol
•
•
Every computer on the Internet has
a unique identifier, its Internet
address (IP address)
The Internet protocol (IP) routes
packets from one computer to
another
– A router is a special-purpose
computer which acts as an
intermediary between a pair of
communicating computers
The Internet is a packet-switching
network. Packets sent between two
computers do not necessarily follow
the same path.
•
An IP packet includes:
– The identity of the sender machine –
i.e. it’s IP address
– The identity of the machine to which
the packet should be delivered
– The packet contents – application
data
•
The maximum size permitted for an
IP packet is 64Kb
– In practice, this is too much for many
networks to deliver in one chunk and
the IP packet must be broken down
into fragments
– The IP protocol takes care of
disassembling a packet into
fragments and subsequently
reassembling the IP packet
6
IP as a basis for a communication
channel
• Performance
– Depends on the underlying networks used
• Reliability
– No validity guarantees
• Where an incoming message buffer is full (at the destination computer or any
intermediate router), the packet will be dropped
– No integrity guarantees
• Packets may be corrupted as they travel through the network; any packet may
arrive more than once at the destination
• Ordering
– No ordering guarantees – a sequence of packets may take different routes,
incurring different transmission times
• Synchronicity
– Over a public network (e.g. the Internet) , asynchronous
– For a closed network, synchronous is possible
7
Chapter 4: Interprocess Communication
•
•
•
•
Introduction
The API for the Internet protocols
External data representation and marshalling
Client-Server communication
8
Elements of C-S Computing
a client, a server, and network
Client
Client machine
•
•
Network
Server
Server machine
Processes follow protocol that defined a set of rules that must be observed by
participants:
– How the data is exchange is encoded?
– How are events (sending, receiving) are synchronized (ordered) so that
participants can send and receive in a coordinated manner?
Face-to-face communication, humans beings follow unspoken protocol based on
eye contact, body language, gesture.
9
Client/sever model
•
•
•
Client asks (request) – server provides (response)
Typically: single server - multiple clients
The server does not need to know anything about the client
– even that it exists
•
The client should always know something about the server
– at least where it is located
10
Networking Basics
•
Physical/Link Layer
– Functionality for the transmission
of signals, representing a stream of
data from one computer to another.
•
Internet/Network Layer
– IP (Internet Protocols) – a packet
of data to be addressed to a remote
computer and delivered.
•
Transport Layer
– Functionalities for delivering data
packets to a specific process on a
remote computer.
– TCP (Transmission Control
Protocol)
– UDP (User Datagram Protocol)
– Programming Interface:
• Sockets
•
• TCP/IP Stack
Applications Layer
Application
(http,ftp,telnet,…)
Transport
(TCP, UDP,..)
Internet/Network
(IP,..)
Physical/Link
(device driver,..)
– Message exchange between
standard or user applications:
• HTTP, FTP, Telnet
11
Networking Basics
• TCP (Transmission
Control Protocol) is a
connection-oriented
communication protocol
that provides a reliable
flow of data between two
computers.
• Example applications:
– HTTP
– FTP
– Telnet
• TCP/IP Stack
Application
(http,ftp,telnet,…)
Transport
(TCP, UDP,..)
Internet/Network
(IP,..)
Physical/Link
(device driver,..)
12
Networking Basics
• UDP (User Datagram Protocol)
is a connectionless
communication protocol that
sends independent packets of
data, called datagrams, from
one computer to another with
no guarantees about arrival or
order of arrival.
• Similar to sending multiple
emails/letters to a friends, each
containing part of a message.
• Example applications:
– Clock server
– Ping
• TCP/IP Stack
Application
(http,ftp,telnet,…)
Transport
(TCP, UDP,..)
Network
(IP,..)
Link
(device driver,..)
13
Network Layering
7
Application
Application
6
Presentation
Presentation
5
Session
Session
4
Transport
Transport
3
Network
Network
Network
2
Data link
Data link
Data link
1
Physical
Physical
Physical
14
Network Layering
• Why layering?
7
Application
Application
6
Presentation
Presentation
5
Session
Session
4
Transport
Transport
3
Network
Network
Network
2
Data link
Data link
Data link
1
Physical
Physical
Physical
15
Layering Makes it Easier
• Application programmer
– Doesn’t need to send IP packets
– Doesn’t need to send Ethernet frames
– Doesn’t need to know how TCP implements
reliability
• Only need a way to pass the data down
– Socket is the API to access transport layer
functions
16
What Lower Layer Need to
Know?
• We pass the data down. What else does the
lower layer need to know?
17
What Lower Layer Need to
Know?
• We pass the data down. What else does the
lower layer need to know?
• How to identify the destination process?
– Where to send the data? (Addressing)
– What process gets the data when it is there?
(Multiplexing)
18
Identify the Destination
• Addressing
– IP address
– hostname (resolve to IP address via DNS)
• Multiplexing
– port
Server socket address
Client socket address
208.216.181.15:80
128.2.194.242:3479
Client
FTP Server
(port 21)
HTTP Server
Connection socket pair
(port 80)
(128.2.194.242:3479, 208.216.181.15:80)
Client host address
128.2.194.242
Server host address
208.216.181.15 19
Understanding Ports
• The TCP and UDP
protocols use ports to
map incoming data to
a particular process
running on a
app
app
computer.
port
port
server
P
o
r
t
app
app
port
port
TCP
Client
TCP or UDP
Packet
Data
port#
data
Understanding Ports
• Port is represented by a positive (16-bit) integer
value
• Some ports have been reserved to support
common/well known services:
–
–
–
–
–
ftp 21
telnet 23
smtp 25
login 513
http 80
• User level process/services generally use port
number value >= 1024
21
Ports
• A port serves as a message
source or destination
Web browser
– With the Internet protocols,
messages are sent to (Internet
address, port) pairs
• A local port can be bound to
no more than one process
• Processes may use multiple
ports
Port
Agreed
(destination)
port
Web browser
Web server
Mail server
Internet
address
138.37.94.248
22
Chapter 3: Interprocess Communication
•
•
•
•
Introduction
The API for the Internet protocols
External data representation and marshalling
Client-Server communication
23
Sockets
• How to use sockets
– Setup socket
• Where is the remote machine (IP address, hostname)
• What service gets the data (port)
– Send and Receive
• Designed just like any other I/O in unix
• send -- write
• recv -- read
– Close the socket
24
Sockets
• Sockets provide an interface for programming networks at
the transport layer.
• Network communication using Sockets is very much
similar to performing file I/O
– In fact, socket handle is treated like file handle.
– The streams used in file I/O operation are also applicable to
socket-based I/O
• Socket-based communication is programming language
independent.
– That means, a socket program written in Java language can also
communicate to a program written in Java or non-Java socket
program.
25
The Socket API
• A socket API provides a programming
construct termed a socket. A process
wishing to communicate with another
process must create an instance, or
instantiate, such a construct.
• The two processes then issue operations
provided by the API to send and receive
data.
26
The conceptual model of the socket API
Process A
Process B
a socket
27
Sockets
browser
• A socket is a programming
abstraction which provides an
endpoint for communication
• The receiver process’ socket must
be bound to a local port and the
Internet address of the computer
on which the receiver runs
• Messages sent to a particular
Internet address and port number
can be received only by a process
whose socket is bound to that
Internet address and port number
• A socket is associated with a
transport protocol – either TCP or
UDP
Socket bound to
(138.37.94.248, 80)
Port
80
Web server
138.37.94.248
browser
28
Socket types
• Datagram socket – using UDP
–
–
–
–
–
Not sequenced
Not reliable
Not unduplicated
Connectionless
Border preserving
• Stream socket – using TCP
–
–
–
–
–
Sequenced
Reliable
Unduplicated
Connection-oriented
Not border preserving
• Raw and others
(extracurricular)
29
Socket Communication
• A server (program) runs on a specific
computer and has a socket that is bound to a
specific port. The server waits and listens to
the socket for a client to make a connection
request.
port
server
Connection request
Client
30
Socket Communication
• If everything goes well, the server accepts the connection.
Upon acceptance, the server gets a new socket bounds to a
different port. It needs a new socket (consequently a
different port number) so that it can continue to listen to
the original socket for connection requests while serving
the connected client.
port
port
port
server
Client
Connection
31
Sockets and Java Socket Classes
• A socket is an endpoint of a two-way
communication link between two programs
running on the network.
• A socket is bound to a port number so that
the TCP layer can identify the application
that data destined to be sent.
• Java’s .net package provides two classes:
– Socket – for implementing a client
– ServerSocket – for implementing a server
32