introduction the api for the internet protocols external data representation and marshalling

32
• Introduction • The API for the Internet protocols • External data representation and marshalling • Client-Server communication • Group communication • Case study: interprocess communication in Java Chapter 4: Interprocess Communication 1

Upload: luke-boyer

Post on 15-Mar-2016

31 views

Category:

Documents


0 download

DESCRIPTION

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. Introduction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction The API for the Internet protocols External data representation and marshalling

• Introduction• The API for the Internet protocols• External data representation and marshalling• Client-Server communication• Group communication• Case study: interprocess communication in Java

Chapter 4: Interprocess Communication

1

Page 2: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 3: Introduction The API for the Internet protocols External data representation and marshalling

Internet Applications Serving Local and Remote Users

Internet Server

PC client

Local Area Network

PDA3

Page 4: Introduction The API for the Internet protocols External data representation and marshalling

• 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

The characteristics of interprocess communication

4

Page 5: Introduction The API for the Internet protocols External data representation and marshalling

• 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

• 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

Process p Process q

Communication channel

send

Outgoing message buffer Incoming message buffer

receivem Message

(sequence of bytes)

5

Page 6: Introduction The API for the Internet protocols External data representation and marshalling

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

• 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

The Internet is a packet-switching network. Packets sent between two computers do not necessarily follow

the same path.

6

Page 7: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 8: Introduction The API for the Internet protocols External data representation and marshalling

• Introduction• The API for the Internet protocols• External data representation and marshalling• Client-Server communication

Chapter 4: Interprocess Communication

8

Page 9: Introduction The API for the Internet protocols External data representation and marshalling

NetworkReq

uest

Result

a client, a server, and network

ClientServer

Client machine Server machine

Elements of C-S Computing

• 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

Page 10: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 11: Introduction The API for the Internet protocols External data representation and marshalling

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• Applications Layer

– Message exchange between standard or user applications:

• HTTP, FTP, Telnet

• TCP/IP Stack

Application

(http,ftp,telnet,…)

Transport

(TCP, UDP,..)

Internet/Network

(IP,..)

Physical/Link

(device driver,..)

11

Page 12: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 13: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 14: Introduction The API for the Internet protocols External data representation and marshalling

Network Layering

Application

Presentation

Session

Transport

Network

Data link

Physical1

2

3

4

5

6

7

Network

Data link

Physical

Application

Presentation

Session

Transport

Network

Data link

Physical

14

Page 15: Introduction The API for the Internet protocols External data representation and marshalling

Network Layering

• Why layering?Application

Presentation

Session

Transport

Network

Data link

Physical1

2

3

4

5

6

7

Network

Data link

Physical

Application

Presentation

Session

Transport

Network

Data link

Physical

15

Page 16: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 17: Introduction The API for the Internet protocols External data representation and marshalling

What Lower Layer Need to Know?

• We pass the data down. What else does the lower layer need to know?

17

Page 18: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 19: Introduction The API for the Internet protocols External data representation and marshalling

Identify the Destination

Connection socket pair

(128.2.194.242:3479, 208.216.181.15:80)

HTTP Server

(port 80)Client

Client socket address

128.2.194.242:3479

Server socket address

208.216.181.15:80

Client host address

128.2.194.242

Server host address

208.216.181.15

FTP Server

(port 21)

• Addressing– IP address– hostname (resolve to IP address via DNS)

• Multiplexing– port

19

Page 20: Introduction The API for the Internet protocols External data representation and marshalling

Understanding Ports

• The TCP and UDP protocols use ports to map incoming data to a particular process running on a computer.

server

Port Client

TCP

TCP or UDP

port port port port

app app app app

port# dataData

Packet

20

Page 21: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 22: Introduction The API for the Internet protocols External data representation and marshalling

Ports• A port serves as a message

source or destination– 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

Web server

Mail server

Web browser

Web browser

138.37.94.248

Port

Agreed (destination)

port

Internet address

22

Page 23: Introduction The API for the Internet protocols External data representation and marshalling

• Introduction• The API for the Internet protocols• External data representation and marshalling• Client-Server communication

Chapter 3: Interprocess Communication

23

Page 24: Introduction The API for the Internet protocols External data representation and marshalling

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 socket24

Page 25: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 26: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 27: Introduction The API for the Internet protocols External data representation and marshalling

The conceptual model of the socket API

a s o c k et

P r o c es s A P r o c es s B

27

Page 28: Introduction The API for the Internet protocols External data representation and marshalling

Sockets

• 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

browser

138.37.94.248

browser

Port 80

Socket bound to (138.37.94.248, 80)

Web server

28

Page 29: Introduction The API for the Internet protocols External data representation and marshalling

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

Page 30: Introduction The API for the Internet protocols External data representation and marshalling

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.

serverClient

Connection requestport30

Page 31: Introduction The API for the Internet protocols External data representation and marshalling

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.

server

ClientConnection

port

port port

31

Page 32: Introduction The API for the Internet protocols External data representation and marshalling

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