Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved. 0136012671 Chapter 3 Inter-process Communication.

Slides:



Advertisements
Similar presentations
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
Advertisements

Remote Procedure Call (RPC)
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
Tam Vu Remote Procedure Call CISC 879 – Spring 03 Tam Vu March 06, 03.
Network Programming Chapter 11 Lecture 6. Networks.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Chapter 2: Communications
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.
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L23 (Chapter 25) Networking.
Networking Support In Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
02/02/2004CSCI 315 Operating Systems Design1 Interprocesses Communication Notice: The slides for this lecture have been largely based on those accompanying.
Client-Server Communication Sockets Remote Procedure Calls Remote Method Invocation (Java)
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
02/01/2010CSCI 315 Operating Systems Design1 Interprocess Communication Notice: The slides for this lecture have been largely based on those accompanying.
Distributed systems (NET 422) Prepared by Dr. Naglaa Fathi Soliman Princess Nora Bint Abdulrahman University College of computer.
Gursharan Singh Tatla Transport Layer 16-May
Process-to-Process Delivery:
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
Fundamentals of Computer Networks ECE 478/578 Lecture #19: Transport Layer Instructor: Loukas Lazos Dept of Electrical and Computer Engineering University.
The Socket API Unit – Background 4.2 The Socket Metaphor In IPC
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Chapter 4: Interprocess Communication‏ Pages
Distributed Systems Concepts and Design Chapter 4.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
3.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8 th Edition Chapter 3: Processes.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
1 11/1/2015 Chapter 4: Processes l Process Concept l Process Scheduling l Operations on Processes l Cooperating Processes l Interprocess Communication.
Chapter 5: Distributed objects and remote invocation Introduction Remote procedure call Events and notifications.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Distributed systems (NET 422) Prepared by Dr. Naglaa Fathi Soliman Princess Nora Bint Abdulrahman University College of computer.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
 Process Concept  Process Scheduling  Operations on Processes  Cooperating Processes  Interprocess Communication  Communication in Client-Server.
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.
1 Kyung Hee University Chapter 11 User Datagram Protocol.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
1 Network Communications A Brief Introduction. 2 Network Communications.
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
Topic 2: Interposes Communication Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Object-Orientated Analysis, Design and Programming
The Transport Layer Implementation Services Functions Protocols
MCA – 405 Elective –I (A) Java Programming & Technology
The Socket API 9/17/2018.
Unicast VS Multicast.
Chapter 4: Processes Process Concept Process Scheduling
Process-to-Process Delivery:
Remote invocation (call)
Process-to-Process Delivery: UDP, TCP
Computer Networks Protocols
Presentation transcript:

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 3 Inter-process Communication 1 Reference slides from Distributed systems concepts and design Distributed computing Liu, and operating system concepts Silberschatz

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Middleware layer 2 This chapter is concerned with the characteristics of protocols for communication between processes. E.g. Java API RMI and RPC is concerned with integrating communication into a programming language paradigm. Under RMI and RPC, there are sockets, message passing, multicast support. Protocols for the representation of collections of data objects in messages are also discussed.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Synchronous and Asynchronous Synchronous and Asynchronous communication: Sending and receiving processes may be either one of them. Synchronous: two processes synchronize at every message. Both send and receive are blocking operations. Whenever a send issued the sending process is blocked until the receive is issued. Whenever a receive is issued by a process, it blocks until a message arrives. Asynchronous: The send operation is non-blocking and the sending process is allowed to proceed as soon as the message has been copied to a local buffer. The receive can be either blocking or non- blocking(process can proceed and notified by polling or interrupt when background buffer filled. But no advantage due to multi-thread and overhead of implementing the mechanism). 3

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Sockets and ports 4 message agreed port any port socket Internet address = Internet address = other ports client server Both UDP and TCP use the socket as endpoints for communication between processes. A socket is associated with a Internet address and port number. Each computer has a large number 2^16 of possible port numbers. Processes may use the same socket for sending and receiving messages.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved TCP TCP stream of bytes communication A dedicated point-to-point channel Use TCP (Transmission Control Protocol) for data transmission. For integrity, checksum is used to detect and reject corrupt packets an sequence numbers to detect and reject duplicate packets. For validity, timeouts and retransmission to deal with lost packets. So messages are guaranteed to be delivered. Lossless and reliable. Sent and received in the same order. Use of TCP: many frequently used services run over TCP connections HTTP, FTP, Telnet, SMTP 5

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved UDP UDP datagram communication: attractive due to no overheads associated with guaranteed message delivery No dedicated point-to-point channel Use UDP (User Datagram Protocol) for data transmission. No acknowledge and retries. Omission failure as messages may be dropped occasionally either because of checksum error or no buffer space at source or destination Messages can be sometimes be delivered out of sender order So applications using UDP are left to provide their own checks to achieve quality of reliable communication that suffers from omission failures, which can be constructed by using acknowledgements. Applications that are acceptable to have occasional omission failure and out of order. For example, DNS and Voice Over IP (VOIP) 6

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Client/Server Communications: TCP 7 The server must be running when a client starts. The server waits for a connection request from a client. To establish a server, you need to create a server socket and attach it to a port, which is where the server listens for connections. After a server socket is created, the server can use this statement to listen for connections. The client issues this statement to request a connection to a server. After the server accepts the connection, communication between server and client is conducted the same as for I/O streams.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Data Transmission through Sockets 8 InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream();

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved A TCP Client/Server Example 9 Problem: Write a client to send data to a server. The server receives the data, uses it to produce a result, and then sends the result back to the client. The client displays the result on the console. In this example, the data sent from the client is the radius of a circle, and the result produced by the server is the area of the circle.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved A Client/Server Example, cont. 10 Server Code Client Code Note: Start the server, then the client. Start Server Start Client

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved The InetAddress Class 11 Occasionally, you would like to know who is connecting to the server. You can use the InetAddress class to find the client's host name and IP address. The InetAddress class models an IP address. You can use the statement shown below to create an instance of InetAddress for the client on a socket. InetAddress inetAddress = socket.getInetAddress(); Next, you can display the client's host name and IP address, as follows: System.out.println("Client's host name is " + inetAddress.getHostName()); System.out.println("Client's IP Address is " + inetAddress.getHostAddress());

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Serving Multiple Clients 12 Multiple clients are quite often connected to a single server at the same time. Typically, a server runs constantly on a server computer, and clients from all over the Internet may want to connect to it. You can use threads to handle the server's multiple clients simultaneously. Simply create a thread for each connection. Here is how the server handles the establishment of a connection: while (true) { Socket socket = serverSocket.accept(); Thread thread = new Thread(new ThreadClass(socket)); thread.start(); } The server socket can have many connections. Each iteration of the while loop creates a new connection. Whenever a connection is established, a new thread is created to handle communication between the server and the new client; and this allows multiple connections to run at the same time.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Example: Serving Multiple Clients 13 Server for Multiple Clients Note: Start the server first, then start multiple clients. Start Server Start Client

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved DatagramPacket 14 The DatagramPacket class represents a datagram packet. Datagram packets are used to implement a connectionless packet delivery service. Each message is routed from one machine to another based solely on information contained within the packet.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved DatagramSocket 15 The DatagramSocket class represents a socket for sending and receiving datagram packets. A datagram socket is the sending or receiving point for a packet delivery service. Each packet sent or received on a datagram socket is individually addressed and routed. Multiple packets sent from one machine to another may be routed differently, and may arrive in any order. To create a server DatagramSocket, use the constructor DatagramSocket(int port), which binds the socket with the specified port on the local host machine. To create a client DatagramSocket, use the constructor DatagramSocket(), which binds the socket with any available port on the local host machine. DatagramSocket Create a server DatagramSocket Create a client DatagramSocket

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Sending and Receiving a DatagramSocket 16 To send data, you need to create a packet, fill in the contents, specify the Internet address and port number for the receiver, and invoke the send(packet) method on a DatagramSocket. To receive data, create an empty packet and invoke the receive(packet) method on a DatagramSocket. Sending Receiving

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Datagram Programming 17 Datagram programming is different from stream socket programming in the sense that there is no concept of a ServerSocket for datagrams. Both client and server use DatagramSocket to send and receive packets. Designate on a server

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Example: A Client/Server Example 18 Already present a client program and a server program using socket streams. The client sends radius to a server. The server receives the data, uses them to find the area, and then sends the area to the client. Rewrite the program using datagram sockets. Server CodeClient Code Note: Start the server, then the client. Start ServerStart Client

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Client/Server Communications Both forms of communication UDP and TCP use the socket abstraction, which provides endpoint for communication between processes. Each socket is associated with a particular protocol either UDP or TCP. Each Internet host has 2^16 (65,535) logical ports. Each port is identified by a number between 1 and 65535, and can be allocated to a particular process. Port numbers between 1 and 1023 are reserved for processes which provide well-known services such as finger, FTP, HTTP, and . 19

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Ports Assignment 20

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Case Studies: Distributed TicTacToe Games 21 TicTacToeServer Run Server TicTacToeClientRun Client

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Distributed TicTacToe Game 22

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Distributed TicTacToe, cont. 23

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Synchronization Revisit Message passing may be either blocking or non-blocking Blocking is considered synchronous Blocking send has the sender block until the corresponding receive is issued Blocking receive has the receiver block until a message arrives Non-blocking is considered asynchronous Non-blocking sender proceeds after send operation (message is copied to local buffer). So the message transmission can run parallel with the sender program Non-blocking receiving process proceeds after receive operation, which provides a buffer to be filled in the background. But it must separately receive notification that its buffer has been filled by polling or interrupt In multiple thread process, blocking receive has no disadvantage. Simple synchronization and less complexity. So today system do not generally provide non- blocking receive.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Buffering Queue of messages attached to the link; implemented in one of three ways 1.Zero capacity – 0 messages Sender must wait for receiver (rendezvous) 2.Bounded capacity – finite length of n messages Sender must wait if link full 3.Unbounded capacity – infinite length Sender never waits

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Remote Procedure Calls Remote procedure call (RPC) abstracts procedure calls between processes on networked systems. Stubs – client-side proxy for the actual procedure on the server. The client-side stub locates the server and marshalls the parameters. The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Marshalling Parameters

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Remote Method Invocation Remote Method Invocation (RMI) is a Java mechanism similar to RPCs. RMI allows a Java object on one machine to invoke a method on a remote object.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Data transmitted on the network is a binary stream. Because different computers may have different internal storage format for the same data type, an external representation of data may be necessary. Data marshalling is the process of translating/ converting the data to an external representation. Data unmarshalling is the process of rebuilding of data structure. Three approaches to external data representation schemes are: a. CORBA’s common data representation: can represent all data types for argument and return values for RMI in CORBA for a variety of programming languages. b. Java’s object serialization: flatterning of an object into a serial form that can be transmitted in a message and stored on disk. It is for use only by Java. Types information is included. c. XML (Extensible Markup Language): define a self-describing textual format for structured data for web use. External Data Representation and marshalling

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Example: Person Object Struct Person { String name; String place; Unsigned long year; }; 30

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved CORBA Common Data Representation (CDR) message The flattened form represents aPerson struct with value: {‘Smith’, ‘London’, 1934} 0–3 4–7 8–11 12–15 16– –27 5 "Smit" "h___" 6 "Lond" "on__" 1934 index in sequence of bytes4 bytes notes on representation length of string ‘Smith’ length of string ‘London’ unsigned long

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Java serialized form The true serialized form contains additional type markers; h0 and h1 are handles Serialized values Person byte version number int year 5 Smith java.lang.String name: 6 London h0 java.lang.String place: h1 Explanation class name, version number number, type and name of instance variables values of instance variables public class Person implements Serializable { private String name; private String place; private int year; public Person() { }

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved XML definition of the Person structure Smith London 1934 Elements: portion of character data surrounded by start and end tag. Hierarchical structure is possible with element enclosing. Attributes: start tag may include associated attribute names and values. E.g. id=“ ”

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Example: Passing Objects in Network Programs 34 Write a program that collects student information from a client and send them to a server. Passing student information in an object. Student Sever Student Class Start Server Note: Start the server first, then the client. Start ClientStudent Client

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Secure Sockets 35 Secure sockets perform encryption on the data transmitted. The Java TM Secure Socket Extension (JSSE) is a Java package that enables secure Internet communications. It implements a Java version of SSL (Secure Sockets Layer) and TLS (Transport Layer Security) protocols It includes functionalities for data encryption, server authentication, message integrity, and optional client authentication. Using JSSE, developers can provide for the secure passage of data between a client and a server running any application protocol.

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Secure Sockets 36 Import javax.net.ssl; Class SSLServerSocket is a subclass of ServerSocket, and inherits all its methods. Class SSLSocket is a subclass of Socket, and inherits all its methods. Example code available: /security/jsse/JSSERefGuide.html#UnsecureSecure