introduction to interprocess communication

16
Introduction to Interprocess communication SE-2811 Dr. Mark L. Hornick 1

Upload: odelia

Post on 22-Feb-2016

50 views

Category:

Documents


0 download

DESCRIPTION

Introduction to Interprocess communication. How do the objects within an application communicate?. Approaches you may have already used. Object A calls a method of Object B, supplying Object C (data) as method argument Object A and Object B both access Object C (a shared data object) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to  Interprocess  communication

Introduction to Interprocess communication

SE-2811Dr. Mark L. Hornick

1

Page 2: Introduction to  Interprocess  communication

How do the objects within an application communicate?

SE-2811Dr. Mark L. Hornick

2

Page 3: Introduction to  Interprocess  communication

Approaches you may have already used1. Object A calls a method of Object B, supplying

Object C (data) as method argument

2. Object A and Object B both access Object C (a shared data object)

Object A creates/modifies (“writes”) Object C Object B “reads” Object C

This approach can be used to exchange data between threads, by using wait/notify to synchronize the writing/reading of the data

SE-2811Dr. Mark L. Hornick

3

Page 4: Introduction to  Interprocess  communication

Another way to exchange data1. Object A writes to a file; Object B reads from

the fileThis approach can also be used to exchange data between processes, since the physical file exists outside the life of a process

Actually, Object A writes to an output stream connected to a file, while Object B reads from an input stream also connected to that file

SE-2811Dr. Mark L. Hornick

4

Page 5: Introduction to  Interprocess  communication

A stream is a serial sequence of data

SE-2811Dr. Mark L. Hornick

5

Input Streams are used to read data from a source

Output Streams are used to write data to a destination

Page 6: Introduction to  Interprocess  communication

A File is just a particular case of the source or destination of an I/O stream

SE-2811Dr. Mark L. Hornick

6

Under the hood, we are really writing to and reading data to the sectors and tracks of hardware device – a drive.

The stream and File objects abstract the detail in an easier-to-use form.The java.io package contains many stream classes that abstract these operations differently: DataXXputStream, ObjectXXputStream, PrintStream

Page 7: Introduction to  Interprocess  communication

What other computer hardware deals with sequential bits and bytes?

SE-2811Dr. Mark L. Hornick

7

Page 8: Introduction to  Interprocess  communication

More generally, streams can be connected to a number of serial devices:

Files Keyboards Consoles Serial ports WAN ports Memory

SE-2811Dr. Mark L. Hornick

8

Page 9: Introduction to  Interprocess  communication

Piped Streams don’t use files at all

A object can write to a piped output stream to send data directly to another object reading a piped input stream The piped output stream must be

connected to a piped input streamEssentially, the output pipe writes to a memory buffer (not a file) and the input pipe reads from that buffer The output and input pipe can be accessed

from separate threadsSE-2811

Dr. Mark L. Hornick9

Page 10: Introduction to  Interprocess  communication

Demo

SE-2811Dr. Mark L. Hornick

10

Page 11: Introduction to  Interprocess  communication

Limitation of Java piped I/O

Some underlying OS’s support the concept of named pipes, which allows: An output pipe to be written from within one

process An input pipe to be read from within a second

processJava’s pipes are not named and do not support the

concept of named pipes directly, so Java piped I/O is generally used for inter-thread data exchange

SE-2811Dr. Mark L. Hornick

11

Page 12: Introduction to  Interprocess  communication

A socket is a higher-level abstraction of the end-point of a two-way communication link between a data source and a destination

As with Files, streams are used to read from and write to sockets

Each socket uses two streams An input stream for reading data coming

into the socket An output stream for writing data to

another socket

SE-2811Dr. Mark L. Hornick

12

Page 13: Introduction to  Interprocess  communication

Data is sent from one socket to another

Each socket can be implemented in a separate process Allowing two processes to exchange

dataThe two processes do not have to be running on the same computer Allowing processes on separate

computers, connected by a network, to exchange data

SE-2811Dr. Mark L. Hornick

13

Page 14: Introduction to  Interprocess  communication

Every socket has a unique identifier

A socket on one computer connects to a socket on a another computer by locating it by its identifier URL – Uniform Resource LocatorSome examples of a URL: www.msoe.edu – a DNS name 192.168.2.101 – an IP address 127.0.0.1 – the self-address of every computer

SE-2811Dr. Mark L. Hornick

14

Page 15: Introduction to  Interprocess  communication

A single computer has a single URL

But can support many sockets Each socket is assigned a port number Port numbers can range from 0 – 65535Some port numbers are reserved for sockets used in well-known applications

Web servers and browsers use port 80 for data exchange using the http protocol

FTP clients and servers use ports 20 and 21 for file data transfer and file transfer commands

The first 1024 ports are reserved for these well-known applications

SE-2811Dr. Mark L. Hornick

15

Page 16: Introduction to  Interprocess  communication

Once an application locates a specific socket, it can access it’s streams and read and write to that socket

Demo

SE-2811Dr. Mark L. Hornick

16