1 Tuesday, December 16, 2008 The practical scientist is trying to solve tomorrow's problem on yesterday's computer. Computer scientists often have it the.

Slides:



Advertisements
Similar presentations
INTERPROCESS COMMUNICATION
Advertisements

INTERPROCESS COMMUNICATION
Inter Process Commonication
Network Programming Chapter 11 Lecture 6. Networks.
Chapter 2: Communications
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
Socket Programming.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
1 Java Networking – Part I CS , Spring 2008/9.
Internetworking (Contd) Chapter 4. Figure 3.26 ATM protocol layers.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
OCT Information System Management 1 Organizational Communications and Distributed Object Technologies Week 5: Inter-process Communications.
CSS434 IPC1 CSS434 Interprocess Communication Textbook Ch4 Professor: Munehiro Fukuda.
CS Distributed Computing Systems Chapter 4: Interprocess Communication Chin-Chih Chang, From Coulouris, Dollimore and Kindberg.
Distributed systems (NET 422) Prepared by Dr. Naglaa Fathi Soliman Princess Nora Bint Abdulrahman University College of computer.
OCT -- OCT Chapter 4 Coulouris Interprocess Communication.
Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
2: Application Layer 1 Socket Programming TCP and UDP.
1 Inter-Process Communication: Network Programming using TCP Java Sockets Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 3 Inter-process Communication.
Socket programming 1. getByName import java.net.*; public class GetHostName { public static void main (String args[]) { String host = "
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
IP and Errors IP Best Effort Datagrams can be: –Lost –Delayed –Duplicated –Delivered out of order –Corrupted.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
Introduction to Networks CS587x Lecture 1 Department of Computer Science Iowa State University.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Slides for Chapter 4: Interprocess Communication
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
Chapter 4: Interprocess Communication‏ Pages
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
Distributed Systems Concepts and Design Chapter 4.
Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Addison-Wesley.
Slides for Chapter 4: Interprocess Communication
Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Addison-Wesley.
Chapter 3: Interprocess Communication
Source: George Colouris, Jean Dollimore, Tim Kinderberg & Gordon Blair (2012). Distributed Systems: Concepts & Design (5 th Ed.). Essex: Addison-Wesley.
Chapter 15 – Part 2 Networks The Internal Operating System The Architecture of Computer Hardware and Systems Software: An Information Technology Approach.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved Interprocess.
Chapter 2 Applications and Layered Architectures Sockets.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 4: Interprocess.
1 Lecture 4: Interprocess Communication Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Addison-Wesley.
Hwajung Lee.  Interprocess Communication (IPC) is at the heart of distributed computing.  Processes and Threads  Process is the execution of a program.
Distributed systems (NET 422) Prepared by Dr. Naglaa Fathi Soliman Princess Nora Bint Abdulrahman University College of computer.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore, Kindberg Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley.
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
03 – Remote invoaction Request-reply RPC RMI Coulouris 5
Unicast VS Multicast.
Text extensions to slides © David E. Bakken,
Slides for Chapter 4: Interprocess Communication
Outline Introduction Networking Basics Understanding Ports and Sockets
سوکت (ارتباط بین کاربردها)
Text extensions to slides © David E. Bakken,
Distributed Objects: Communication and System Support
Socket Programming.
Distributed Objects: Communication and System Support
Slides for Chapter 4: Interprocess Communication
Review Communication via paired sockets, one local and one remote
Presentation transcript:

1 Tuesday, December 16, 2008 The practical scientist is trying to solve tomorrow's problem on yesterday's computer. Computer scientists often have it the other way around. - Numerical Recipes, C Edition

Distributed Computing Class: BSIT-8 Instructor: Raihan Ur Rasool Chapter 04: Inter-process Communication

Chapter 3 SELF STUDY Chapter 3 – SELF STUDY 3  Networking issues for distributed systems  Types of network  Network Principles  Protocol layers  Internetworking  Routing  Internet protocols  Case Studies  Ethernet  MobileLAN  ATM

Objectives of the lecture 4  To study the general characteristics of interprocess communication and the particular characteristics of both datagram and stream communication in the Internet.  To be able to write Java and C applications that use the Internet protocols and Java serialization.  To be aware of the design issues for Request-Reply protocols and how collections of data objects may be represented in messages (RMI and language integration are left until Chapter 5).  To be able to use the Java API to IP multicast and to consider the main options for reliability and ordering in group communication.

5  Introduction  The API for the Internet protocols  External data representation and marshalling  Client-Server communication  Group communication  Case study: interprocess communication in UNIX  Summary Chapter 4: Interprocess Communication

6  Middleware layer  TCP ( UDP) from a programmers point of view  TCP : two way stream  UDP : datagram, message passing  Java interface, UNIX Socket  marshalling and demarshalling  data form translation  Client-Server communication  Request-Reply protocols  Java RMI, RPC  Group communication Introduction

7 Middleware layer (1)

Middleware layer (2) 8  An adapted reference model for networked communication. 2-5

Middleware layer (3) 9  A software layer that  masks the heterogeneity of systems  provides a convenient programming abstraction  provides protocols for providing general-purpose services to more specific applications, e.g. naming, security, transaction, persistent storage and event notification  authentication protocols  authorization protocols  distributed commit protocols  distributed locking protocols  high-level communication protocols  remote procedure calls (RPC)  remote method invocation (RMI)

Middleware (4) 10  General structure of a distributed system as middleware. 1-22

Middleware programming models 11  Remote Calls  remote Procedure Calls (RPC)  distributed objects and Remote Method Invocation (RMI)  eg. Java RMI  Group multicast protocols  Common Object Request Broker Architecture (CORBA)  Other programming models  remote event notification  remote SQL access  distributed transaction processing

12  Introduction  The API for the Internet protocols  External data representation and marshalling  Client-Server communication  Group communication  Case study: interprocess communication in UNIX  Summary Where are we ?

13  Producer—Consumer and wait  Send and receive  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 nonblocking,  receive could be blocking or nonblocking  (receive notification by interrupt)  Java supports multiple threads in a single process  Non-blocking communication appears to be more efficient, but it involves extra complexity in the receiving process: flow control The characteristics of inter-process communication (1)

14  Message destinations:  Internet address + local port  Port has one receiver but many senders  service name: names into server locations at run time  location independent resource 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 order in which they were transmitted by the sender.  The delivery out of sender’s order is regarded as failure The characteristics of interprocess communication (2)

15  Endpoint for communication between processes  Both forms of communication (UDP and TCP ) use the socket abstraction  Originated from BSD Unix, present in Linux, Windows NT and Macintosh OS etc  bound to a local port (2 16 possible port number) and one of the Internet address  a process cannot share socket with other processes on the same computer Socket message agreed port any port socket Internet address = Internet address = other ports client server

Sockets 16  The application level API to TCP & UDP  Allows users to write application “protocol objects” which sit on top of TCP and UDP.  Execution of TCP/UDP/IP are in kernel space. Sockets provide the bridge to user space.  Java provides 3 types of sockets  DatagramSocket – for UDP  ServerSocket – for TCP server  Socket – endpoint of a TCP stream More on Sockets: 

17  UDP datagrams are sent without acknowledgement or retries  Issues relating to datagram communication  Message size: not bigger than 64k in size, otherwise truncated on arrival  blocking: non-blocking sends (message could be discarded at destination if there is not a socket bound to the port ) and blocking receives (could be timeout)  Timeout: receiver set on socket –server blocks forever  Receive from any: not specify an origin for messages, but could be set to receive from or send to particular remote port by socket connection operation UDP datagram communication

18  Failure model  omission failure: message be dropped due to checksum error or no buffer space at sender side or receiver side (send-omission, receive-omission)  ordering: message be delivered out of sender order  application maintains the reliability of UDP communication channel by itself (ACK)  DNS & VOIP are implemented over UDP  UDP datagram do not suffer from overheads associated with guaranteed message delivery

19  DatagramPacket  DatagramSocket  send and receive : transmit datagram between a pair of sockets  setSoTimeout : receive method will block for the time specified and then throw an InterruptedIOexception  connect: connect to a particular remote port and Internet address  Examples  acceptable to services that are liable to occasional omission failures, e.g. DNS Java API for UDP datagrams

Datagram Sockets 20  Creating a datagram socket  DatagramSocket soc = new DatagramSocket(port-no.)  Creating a datagram packect  DatagramPacket p = new DatagramPacket(byte[] data, int len, InetAddress dest, int dest-port);  Sending a packet  soc.send( p )  Receiving a packet  q = new DatagramPacket(buff, len); soc.receive( q );

21 UDP client sends a message to the server and gets a reply import java.net.*; import java.io.*; public class UDPClient{ public static void main(String args[]){ // args give message contents and server hostname DatagramSocket aSocket = null; try { aSocket = new DatagramSocket(); byte [] m = args[0].getBytes(); InetAddress aHost = InetAddress.getByName(args[1]); int serverPort = 6789; DatagramPacket request = new DatagramPacket(m, args[0].length(), aHost, serverPort); aSocket.send(request); byte[] buffer = new byte[1000]; DatagramPacket reply = new DatagramPacket(buffer, buffer.length); aSocket.receive(reply); System.out.println("Reply: " + new String(reply.getData())); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} }finally {if(aSocket != null) aSocket.close();} }

22 UDP server repeatedly receives a request and sends it back to the client import java.net.*; import java.io.*; public class UDPServer{ public static void main(String args[]){ DatagramSocket aSocket = null; try{ aSocket = new DatagramSocket(6789); byte[] buffer = new byte[1000]; while(true){ DatagramPacket request = new DatagramPacket(buffer, buffer.length); aSocket.receive(request); DatagramPacket reply = new DatagramPacket(request.getData(), request.getLength(), request.getAddress(), request.getPort()); aSocket.send(reply); } }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e) {System.out.println("IO: " + e.getMessage());} }finally {if(aSocket != null) aSocket.close();} }

23  The API to the TCP  provide the abstraction of a stream of bytes to which data may be written and from which data may be read  Hidden network characteristics  message sizes (how much data to write/read) (Application)  lost messages (ACK)  flow control (match the speed)  message duplication and ordering (identifier with each IP Packet)  message destinations (establish connection) Once connection is established, no need of address & ports  While connection establishing: client/server  Client  Connect request, Server  Accept request becomes Peers  Client  Connect request, Server  Accept request, becomes Peers  Client: creates stream socket, bind to a port, and makes a connect request to server  Server: creates a listening socket, bind to a server port, and waits for clients TCP stream communication (1)

24  issues related to stream communication  Matching of data items: agree to the contents of the transmitted data (int & double, write/ read, )  Blocking: send blocked until the data is written in the receiver’s buffer, receive blocked until the data in the local buffer becomes available  Threads: server create a new thread for every connection  failure model  integrity and validity have been achieved by checksum, sequence number, timeout and retransmission in TCP protocol  connection could be broken due to unknown failures  Can’t distinguish between network failure and the destination process failure  Can’t tell whether its recent messages have been received or not TCP stream communication (2)

TCP byte stream sockets 25  Server socket – waits for connections  soc = new ServerSocket( port-no );  Socket newsoc = soc.accept( );  Client socket – connects to server  client = new Socket(server-addr, server-port);  When connected, get streams  InputStream in = client.getInputStream( ); OutputStream out = client.getOutputStream( )

26  ServerSocket  accept: listen for connect requests from clients  Socket  constructor  not only create a socket associated with a local port, but also connect it to the specified remote computer and port number  getInputStream  getOutputStream Java API for TCP Streams

27 TCP client makes connection to server, sends request and receives reply import java.net.*; import java.io.*; public class TCPClient { public static void main (String args[]) { // arguments supply message and hostname of destination Socket s = null; try{ int serverPort = 7896; s = new Socket(args[1], serverPort); DataInputStream in = new DataInputStream( s.getInputStream()); DataOutputStream out = new DataOutputStream( s.getOutputStream()); out.writeUTF(args[0]); // UTF is a string encoding see Sn 4.3 String data = in.readUTF(); System.out.println("Received: "+ data) ; }catch (UnknownHostException e){ System.out.println("Sock:"+e.getMessage()); }catch (EOFException e){System.out.println("EOF:"+e.getMessage()); }catch (IOException e){System.out.println("IO:"+e.getMessage());} }finally {if(s!=null) try {s.close();}catch (IOException e){System.out.println("close:"+e.getMessage());}} }

28 TCP server makes a connection for each client and then echoes the client’s request (1) import java.net.*; import java.io.*; public class TCPServer { public static void main (String args[]) { try{ int serverPort = 7896; ServerSocket listenSocket = new ServerSocket(serverPort); while(true) { Socket clientSocket = listenSocket.accept(); Connection c = new Connection(clientSocket); } } catch(IOException e) {System.out.println("Listen :"+e.getMessage());} } // this figure continues on the next slide

29 TCP Server (2) Connection class Connection extends Thread { DataInputStream in; DataOutputStream out; Socket clientSocket; public Connection (Socket aClientSocket) { try { clientSocket = aClientSocket; in = new DataInputStream( clientSocket.getInputStream()); out =new DataOutputStream( clientSocket.getOutputStream()); this.start(); } catch(IOException e) {System.out.println("Connection:"+e.getMessage());} } public void run(){ try { // an echo server String data = in.readUTF(); out.writeUTF(data); } catch(EOFException e) {System.out.println("EOF:"+e.getMessage()); } catch(IOException e) {System.out.println("IO:"+e.getMessage());} } finally{ try {clientSocket.close();}catch (IOException e){/*close failed*/}} }

30  Introduction  The API for the Internet protocols  External data representation and marshalling  Client-Server communication  Group communication  Case study: interprocess communication in UNIX  Summary Where are we ?

31  Why does the communication data need external data representation and marshalling? [data structures must be flattened]  Different data format on different computers, e.g., big-endian/little-endian integer order, ASCII (Unix) / Unicode character coding  How to enable any two computers to exchange data values? 1. The values be converted to an agreed external format before transmission and converted to the local form on receipt 2. The values are transmitted in the sender’s format, together with an indication of the format used, and the receipt converts the value if necessary External data representation and marshalling introduction [ data structures and a sequence of bytes]

32  Why does the communication data need external data representation and marshalling?  Different data format on different computers, e.g., big-endian/little-endian integer order, ASCII (Unix) / Unicode character coding  How to enable any two computers to exchange data values? 1. The values be converted to an agreed external format before transmission and converted to the local form on receipt 2. The values are transmitted in the sender’s format, together with an indication of the format used, and the receipt converts the value if necessary  External data representation  An agreed standard for the representation of data structures and primitive values  Marshalling  The process of taking a collection of data items and assembling them into a form suitable for transmission in a message  Usage: for data transmission or storing in files  Three alternative approaches to EDP  CORBA’s common data representation / Java’s object serialization & XML External data representation and marshalling introduction

Reading Assignment  CORBA’s Common Data Representation (CDR)  Java Object Serialization  Extensible Markup language (XML)  Next Time:  Recap  Client-server communication 33 