CSS434 IPC1 CSS434 Interprocess Communication Textbook Ch4 Professor: Munehiro Fukuda.

Slides:



Advertisements
Similar presentations
CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Advertisements

Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Winter, 2004CSS490 MPI1 CSS490 Group Communication and MPI Textbook Ch3 Instructor: Munehiro Fukuda These slides were compiled from the course textbook,
Socket Programming By Ratnakar Kamath. What Is a Socket? Server has a socket bound to a specific port number. Client makes a connection request. Server.
Inter Process Commonication
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.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
1 Java Networking – Part I CS , Spring 2008/9.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
OCT Information System Management 1 Organizational Communications and Distributed Object Technologies Week 5: Inter-process Communications.
Instructor: Munehiro Fukuda
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
TCP Socket Programming CPSC 441 Department of Computer Science University of Calgary.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Winter, 2004CSS490 Message Passing1 Textbook Ch2 - 3 Instructor: Munehiro Fukuda These slides were compiled from the course textbook, the reference books,
OCT -- OCT Chapter 4 Coulouris Interprocess Communication.
Aalborg Media Lab 15-Jul-15 Java & EyesWeb Lecture 14 Java Client / Server 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.
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
Socket programming 1. getByName import java.net.*; public class GetHostName { public static void main (String args[]) { String host = "
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.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Winter 2002Suprakash Datta1 Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
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.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
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.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
Java Server Programming Web Interface for Java Programs.
Distributed systems (NET 422) Prepared by Dr. Naglaa Fathi Soliman Princess Nora Bint Abdulrahman University College of computer.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
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.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
Java Programming II Java Network (I) Java Programming II.
CSE 501N Fall ‘09 22: Introduction to Networking November Nick Leidenfrost.
Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore, Kindberg Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley.
Socket Programming Client/Server.
Client-server Programming
CSI 4118 – UNIVERSITY OF OTTAWA
Text extensions to slides © David E. Bakken,
Slides for Chapter 4: Interprocess Communication
سوکت (ارتباط بین کاربردها)
Distributed Objects: Communication and System Support
Distributed Objects: Communication and System Support
Slides for Chapter 4: Interprocess Communication
Multiplexing/Demux.
CS18000: Problem Solving and Object-Oriented Programming
Review Communication via paired sockets, one local and one remote
Presentation transcript:

CSS434 IPC1 CSS434 Interprocess Communication Textbook Ch4 Professor: Munehiro Fukuda

CSS434 IPC2 Outline Java sockets Object serialization Blocking/non-blocking communication Buffering Error handling Idenpotency Exactly-one semantics

CSS434 IPC3 Middleware Layers

CSS434 IPC4 Sockets and Ports message agreed port any port socket Internet address = Internet address = other ports client server

CSS434 IPC5 Java TCP Client 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());}} }

CSS434 IPC6 Java TCP Server 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

CSS434 IPC7 Java TCP Server (Cont ’ d) 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*/}} }

CSS434 IPC8 Serialization Manual Operations in C++ class SubObject { public: int id; SubObject( int I ) { id = I; } void print( ) { cout << “SubObject: id=“ << id << endl; } }; class MainObject { public: int id; SubObject *subObj; MainObject( int I, SubObject *s ) { id = I; subObj = j; } void print( ) { cout << “MainObject: id=“ << id << endl; } }; Int main( int argc, char** argv ) { int f1 = create( “sample.dat”, 0744 ); MainObject *obj1 = new MainObject( 1, new SubObject( 2 ) ); write( f1, obj1, sizeof( *obj1 ) ); //manually write data pointed to by obj1 write( f1, obj1->subObj, sizeof( *obj1->subObj ) );//manually write data pointed to by obj1 close( f1 ); int f2 = open( “sample.dat”, O_RDONLY ); MainObject *obj2 = new MainObject( 0, new SubObject( 0 ) ); read( f2, obj2, sizeof( MainObject ) ); //manually read data pointed to by obj2 read( f2, obj2->subObj, sizeof( SubObject ) );//manually read data pointed to by obj2 close( f2 ); obj2->print( ); obj2->subObj->print( ); } MainObj SuObj Read/write

CSS434 IPC9 Serialization Automatic Operations in Java public class SubObject implements Serializable { private int id; public SubObject( int I ) { id = I; } public void print( ) { System.out.println( “SubObject: id =“ + id ); } } public class MainObject implements Serializable { public int id; public SubObject subObj; public MainObject( int I, SubObject s ) { id = I; subObj = s; } public void print( ) { System.out.println( “MainObject: id =“ + id ); } } Public class Test { public static void main( String args[] ) throws IOException, ClassNotFoundException { FileOutputStream f1 = new FileOutputStream( “sample.dat” ); ObjectOutputStream o = new ObjectOutputStream( f1 ); MainObject obj1 = new MainObject( 1, new SubObject( 2 ) ); //automatically write all objects traceable from obj1 o.writeObject( obj1 );//automatically write all objects traceable from obj1 o.flush( ); o.close( ); FileInputStream f2 = new FileInputStream( “sample.dat” ); ObjectInputStream i = new ObjectInputStream( f2 ); // automatically read all object traceable from obj2 MainObject obj2 = (MainObject)I.readObject( ); // automatically read all object traceable from obj2 I.close( ); obj2.print( ); obj2.subObj.print( ); }

CSS434 IPC10 Serialization Serializable or Not Serializable Serializable Classes implementing the Serializable interface Primitive data types such as int and double and their arrays Not Serializable Image and Thread classes Static variables Variables quantified with Transient Zero or null initialized upon a de-serialization

CSS434 IPC11 Blocking/Non-Blocking Communication Blocking communication TCP, UDP, and other communication packages Client: blocked only when the destination buffer is full Server: blocked if no message has arrived from the client. Rendezvous Client: blocked for a server to receive a message Server: blocked if no message has arrived from the client. Non-blocking communication Server does not want to be blocked when It may receive a message from a different client. It has another jobs to be done such as computation or message transmission. Some synchronization is necessary later.

CSS434 IPC12 Non-Blocking Communication C/C++ Example Polling Periodically check if a socket is ready to read data: Example: sd = socket( AF_INET, SOCKET_STREAM, 0); set_fl(sd, O_NONBLOCK);// set the socket as non-blocking struct pollfd pfd; pfd.fd = sd; poll( &pfd, 1, timeout )// poll the socket status Interrupt Notified from the system when a socket is ready to read data; Example: sd = socket(AF_INET, SOCKET_STREAM, 0); signal(SIGIO, sigio_func);// set a future interrupt to call sigio_func( ) fcntl(sd, F_SETOWN, getpid( )); // ask OS to deliver this fd interrupt to me fcntl(sd, F_SETFL, FASYNC);// set this fd asynchronous int sigio_func( ) { // invoked upon an interrupt }

CSS434 IPC13 Non-Blocking Communication Java Example Polling Periodically check if a socket is ready to read data: Example 1: socket = new Socket( server, port ); rawIn = socket.getInputStream( ); in = new DataInputStream( rawIn ); if ( rawIn.available( ) > 0 ) { String str = in.readUTF( ); System.out.println( str ); } Example 2: ServerSocket server = new ServerSocket( port ); server.setSoTimeout( 500 ); //will be blocked for 500ms upon accept Socket client = null; try { client = server.accept( ); } catch ( SocketTimeoutException e ) { } Interrupt Difficult to implement asynchronous/interruptible communication in Java Reason 1: There are no methods corresponding to fctl( ). Reason 2: JVM itself receives external interrupts.

CSS434 IPC14 Buffering No Buffering A message remains on the sender until the receiver issues receive( ). Rendezvous Performance drawback Single Message Buffer The sender can send at most one message even if the receiver has not issued receive( ). Stop-and-wait protocol A message can be kept read in advance. What if the sender has multiple messages? Finite-Bound Buffer Unsuccessful communication- Go-Back-N Technique Flow-controlled communication- sliding window in TCP Socket: capable of changing its buffer size with setsockopt( ) message

CSS434 IPC15 Failure Handling Loss of request message Loss of response message Unsuccessful execution of request Do we really need acknowledgment messages? client server timeout request response ack response timeout request ack response request ack request 2 response 2 request 2 timeout

CSS434 IPC16 Idempotency A pair of request and response is enough to handle faults Idempotency assumed: At-least one semantics Last-one semantics client server client server Timeout request request 2 request 3 request 4 response reesponse 2 request response

CSS434 IPC17 Exactly-One Semantics What if errors in the banking system New semantics required: Exactly-one semantics Server must keep track of the request sequence Withdraw $100 $1000-$100 = $900 Not received Withdraw $100 $900-$100 =$800! $100 received Withdraw995 $100 $1000-$100 = $900 for Trans995 Not received Withdraw995 $100 $100 received Trans995 completed No subtraction

CSS434 IPC18 Exercises (No turn-in) 1. Consider the pros and cons of polling and interrupt in non- blocking communication. 2. Consider an example inducing an accidental system hang- up (named a deadlock) in no-buffering communication. 3. Which of the following operations are idempotent? 1. cin >> data; 2. ifstream infile( “ input.txt ” ); infile.seek( ); 3. cout << data; 4. int a = 1, b = 2, c; c = a + b; 5. int c = 1; c++;