Distributed Systems COMP 212. Lecture 8 Othon Michail

Similar documents
COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

Multi-threaded Web Server (Assignment 1) Georgios Georgiadis

3. Remote Procedure Call

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

Web Server Project. Tom Kelliher, CS points, due May 4, 2011

Chapter 4 Communication

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL

Operating Systems. 18. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Spring /20/ Paul Krzyzanowski

URL Kullanımı Get URL

CS 11 java track: lecture 6

RPC flow. 4.3 Remote procedure calls IDL. RPC components. Procedure. Program. sum (j,k) int j,k; {return j+k;} i = sum (3,7); Local procedure call

protocols September 15,

Networking Basics. network communication.

Distributed Systems 8. Remote Procedure Calls

Lab 1 : Java Sockets

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

Chapter 4: Processes

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2)

CSCD 330 Network Programming Spring 2018

Remote Invocation. Today. Next time. l Indirect communication. l Request-reply, RPC, RMI

Remote Invocation. Today. Next time. l Overlay networks and P2P. l Request-reply, RPC, RMI

Advanced Java Programming. Networking

Java Networking (sockets)

TCP Networking in Java. Some reminders

Distributed Information Processing

Lecture 3: Socket Programming

Java Support for developing TCP Network Based Programs

Distributed Systems. How do regular procedure calls work in programming languages? Problems with sockets RPC. Regular procedure calls

Steps for Implementing a Server

IT101. File Input and Output

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Network Programming: Servers

Chapter 4: Processes. Process Concept. Process State

Distributed Systems are Everywhere!" CS162 Operating Systems and Systems Programming Lecture 22 Client-Server" Client-Server" Message Passing"

CSCD 330 Network Programming Winter 2019

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

TCP connections. Fundamentals of Internet Connections Objectives. Connect to an Echo port. java.net.socket

CHAPTER - 4 REMOTE COMMUNICATION

I/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O

Chapter 2 Applications and

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Lecture 5: Object Interaction: RMI and RPC

Distributed Systems. 03. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Fall 2017

Overview. Communication types and role of Middleware Remote Procedure Call (RPC) Message Oriented Communication Multicasting 2/36

Distributed Systems Lecture 2 1. External Data Representation and Marshalling (Sec. 4.3) Request reply protocol (failure modes) (Sec. 4.

Java Socket Application. Distributed Systems IT332

Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection)

Communication Paradigms

CSCD 330 Network Programming Spring 2018

Communication. Communication. Distributed Systems. Networks and protocols Sockets Remote Invocation Messages Streams. Fall /10/2001 DoCS

} } class ClientHandler extends Thread { private Socket client; private Scanner input; private PrintWriter output;

DISTRIBUTED COMPUTING

416 Distributed Systems. RPC Day 2 Jan 12, 2018

CS2 Advanced Programming in Java note 8

CS 417 9/18/17. Paul Krzyzanowski 1. Socket-based communication. Distributed Systems 03. Remote Procedure Calls. Sample SMTP Interaction

1.00 Lecture 30. Sending information to a Java program

CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2012

Application Layer Introduction; HTTP; FTP

Computer Systems and Networks

CPSC 441 Tutorial TCP Server. Department of Computer Science University of Calgary

Networked Applications: Sockets. End System: Computer on the Net

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

CSPP : Introduction to Object-Oriented Programming

Computer Networks. Wenzhong Li. Nanjing University

Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science

IPC. Communication. Layered Protocols. Layered Protocols (1) Data Link Layer. Layered Protocols (2)

Interprocess Communication

Programming Methods Dr Robert Harle

OBJECT ORIENTED PROGRAMMING

Review of Previous Lecture

Communication. Distributed Systems Santa Clara University 2016

Communication Basics, RPC & RMI. CS403/534 Distributed Systems Erkay Savas Sabanci University

Week 13 Lab - Exploring Connections & Remote Execution

Lecture 15: Network File Systems

C 1. Recap: Finger Table. CSE 486/586 Distributed Systems Remote Procedure Call. Chord: Node Joins and Leaves. Recall? Socket API

Input from Files. Buffered Reader

Internet Protocol. Chapter 5 Protocol Layering. Juho Kim Graduate School of Information & Technology Sogang University

CSE 143 Lecture 22. I/O Streams; Exceptions; Inheritance. read 9.3, 6.4. slides created by Marty Stepp

CSE 143 Lecture 21. I/O Streams; Exceptions; Inheritance. read 9.3, 6.4. slides created by Marty Stepp

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

Web Technology. COMP476 Networked Computer Systems. Hypertext and Hypermedia. Document Representation. Client-Server Paradigm.

Communication. Overview

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

Two Phase Commit Protocol. Distributed Systems. Remote Procedure Calls (RPC) Network & Distributed Operating Systems. Network OS.

COSC 2206 Internet Tools. The HTTP Protocol

public static void main(string[] args) throws IOException { sock = new Socket(args[0], Integer.parseInt(args[1]));

JAVA - NETWORKING (SOCKET PROGRAMMING)

Structured communication (Remote invocation)

Dr Markus Hagenbuchner CSCI319 SIM. Distributed Systems Chapter 4 - Communication

COMP-202: Foundations of Programming. Lecture 22: File I/O Jackie Cheung, Winter 2015

CSE 143 Lecture 25. I/O Streams; Exceptions; Inheritance. read 9.3, 6.4. slides adapted from Marty Stepp

Java Input/Output. 11 April 2013 OSU CSE 1

Lecture 06: Distributed Object

Verteilte Systeme (Distributed Systems)

Remote Invocation. To do. Request-reply, RPC, RMI. q Today q. q Next time: Indirect communication

COMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015

Introduction to Java.net Package. CGS 3416 Java for Non Majors

Advanced Topics in Distributed Systems. Dr. Ayman A. Abdel-Hamid. Computer Science Department Virginia Tech

Lecture 11.1 I/O Streams

Transcription:

Distributed Systems COMP 212 Lecture 8 Othon Michail

HTTP Protocol Hypertext Transfer Protocol Used to transmit resources on the WWW HTML files, image files, query results, Identified by Uniform Resource Locators (URLs) Uses the client-server model HTTP client: a browser HTTP server: a Web server Application layer protocol presuming a reliable underlying transport layer protocol Usually using TCP/IP sockets HTTPS: secure version of HTTP 2/29

An HTTP 1.0 Protocol Request <method> <path to file> <HTTP version> e.g. GET lecture-notes/index.html HTTP/1.0 Response <HTTP version> <response status> <reason phrase>: e.g. HTTP/1.0 200 OK or HTTP/1.0 404 Not Found <Date>: e.g. Monday 6 Feb 2017 10:03:49 GMT <Content-Type>: e.g. text/html <Content-Length>: e.g. 1954 (bytes) <server id> <blank line> <contents of file> 3/29

HTTP 1.0 Toy Server Structure public class WebServer { public static void main(string args[]) throws Exception{ < initialisation & listening > } private static void processrequest(socket myclient) { < read request and reply > } private static void sendfile(inputstream file, OutputStream out) { < copy file to out > } }; 4/29

import java.io.*; import java.net.*; import java.util.*; public class WebServer { private static ServerSocket initsocket (int port) throws IOException { return new ServerSocket (port); }; public static void main(string args[]) throws Exception { if (args.length!= 1) { System.out.println("Usage: WebServer <port_number>"); System.exit(0); } int port = Integer.parseInt(args[0]); System.out.println("Listening on port " + port); // Create a ServerSocket to listen on that port. ServerSocket ss = null; try { ss = initsocket(port); } catch (Exception e) {} while(true){ processrequest(ss.accept()); } }; 5/29

private static void processrequest (Socket myclient){ try { // Get input and output streams to talk to the client from the socket BufferedReader in = new BufferedReader(new InputStreamReader(myClient.getInputStream())); OutputStream out = new BufferedOutputStream(myClient.getOutputStream()); PrintWriter pout = new PrintWriter(out,true); String request = in.readline(); System.out.println("Request: " + request); String req = request.substring(4, request.length()-9).trim(); String path = "html/" + req; File f = new File(path); if (f.isdirectory()) { // if directory, implicitly add 'index.html' path = path + "/" + "index.html"; f = new File(path); } try { InputStream file = new FileInputStream(f); 6/29

pout.println("http/1.0 200 OK"); String contenttype = URLConnection.guessContentTypeFromName(path); System.out.println("Content-Type: " + contenttype); if (contenttype!= null) { pout.println("content-type: + contenttype); } pout.println("date: " + new Date()); pout.println("server: Toy HTTP Server 1.0"); pout.println(); sendfile(file, out); // send raw file } catch (FileNotFoundException e) { System.out.println("File " + path + " not found"); } out.close(); } catch (Exception e) { System.err.println(e); } }; 7/29

private static void sendfile(inputstream file, OutputStream out) { try { byte[] buffer = new byte[1000]; while (file.available() > 0) out.write(buffer, 0, file.read(buffer)); } catch (IOException e) { System.err.println(e); } } }; 8/29

HTTP 1.0 Toy Server Lacks many features HEAD, POST, PUT, DELETE, Forms, CGI, dynamic features Cookies Lacks security Non-persistent communication (defined in 1.1) not supported Fully functional Jetty HTTP server http://www.eclipse.org/jetty/ Tutorial: http://wiki.eclipse.org/jetty/tutorial/embedding_jetty 9/29

Sockets with Java: Summary (1) Server 1. Create a server socket using the ServerSocket constructor (and catch the exceptions) 2. Create the socket object that must be used to communicate with the client and use the accept method to assign the correct value to this socket Client 2. Create a client socket using the Socket constructor (and catch the exceptions) 10/29

Sockets with Java: Summary (2) 3. Create the appropriate input and output streams 4. Write the code that communicates with the client 5. Close the input and output streams 6. Close all the sockets 11/29

Advantages and Disadvantages Main advantage: Sockets are perfect if you want to develop applicationspecific protocols They are fast and efficient Disadvantages: big developing effort if functionality changes application-specific protocols are difficult to maintain do not fit easily into an object-oriented paradigm does not encourage reuse using an application-specific protocol means that the client code can be quite large 12/29

Questions In this simple example we passed strings How to pass an object? Serialisation (converts any object into a string) How do we know then what is sent across the network? Integer, String, Object,? 13/29

Middleware Layer Middleware has been invented to provide common services and protocols that can be used by a rich set of communication protocols, but which allow different applications to communicate Naming protocols, so that different applications can easily share resources Security protocols, to allow different applications to communicate in a secure way Scaling mechanisms, such as support for replication and Caching 14/29

Middleware Protocols An adapted reference model for networked communication 15/29

Middleware Communication RPC (remote procedure calls) RMI (remote method invocation) Java RMI Message-based communication Streams 16/29

RPC: Remote Procedure Call Birrell and Nelson (1984) To allow programs to call procedures located on other machines. Effectively removing the need for the Distributed Systems programmer to worry about all the details of network programming i.e. no more sockets Conceptually simple, but 17/29

Complications: More on RPC Two machine architectures may not (or need not) be identical Each machine can have a different address space How are parameters (of different, possibly very complex, types) passed to/from a remote procedure? What happens if one, the other, or both of the machines crash while the procedure is being called? 18/29

How RPC Works: Part 1 As far as the programmer is concerned: A remote procedure call looks and works identically to a local procedure call. In this was, transparency is achieved 19/29

Client and Server Stubs Client Program Server Program Client stub Communication Module Server stub Communication Module Network communication Client program only communicates with the client stub 20/29

How RPC Works: Part 2 The procedure is split into two parts: The CLIENT stub implements the interface on the local machine through which the remote functionality can be invoked The SERVER stub implements the actual functionality, i.e. does the real work! Parameters are marshalled by the client prior to transmission to the server. 21/29

Flow Chart Principle of RPC between a client and server program no big surprises here 22/29

The Ten Steps of a RPC 1. Client procedure calls client stub in a normal way 2. Client stub builds message, calls local OS 3. Client's OS sends message to remote OS 4. Remote OS gives message to server stub 5. Server stub unpacks parameters, calls server 6. Server does work, returns result to the stub 7. Server stub packs it in message, calls local OS 8. Server's OS sends message to client's OS 9. Client's OS gives message to client stub 10. Stub unpacks result, returns to client 23/29

Passing Value Parameters Steps involved in doing remote computation through RPC 24/29

RPC Problems RPC works really well if all the machines are homogeneous Complications arise when the two machines use different character encodings, e.g. EBCDIC or ASCII Byte-ordering is also a problem: Intel machines are little-endian Sun Sparc s are big-endian Extra mechanisms are required to be built into the RPC mechanism to provide for these types of situations This adds complexity 25/29

Python RPC Server Example import xmlrpclib from SimpleXMLRPCServer import SimpleXMLRPCServer def myadd(x, y): return (x + y) server = SimpleXMLRPCServer(("localhost", 8000)) print "Listening on port 8000..." server.register_function(myadd, "myadd") server.serve_forever() Save the file as server.py and execute it by $ python server.py from the terminal ($ is the command prompt) 26/29

Python RPC client example import xmlrpclib proxy = xmlrpclib.serverproxy("http://localhost:8 000/") print proxy.myadd(2, 3) Save the file as client.py and execute it by $ python client.py 27/29

Interface Definition Language (IDL) RPCs typically require development of custom protocol interfaces to be effective Protocol interfaces are described by means of an Interface Definition Language (IDL) IDLs are language-neutral they do not presuppose the use of any one programming language That said, most IDLs look a lot like C Protocol Buffers (Google) 28/29

RPC Summary The DSs de-facto standard for communication and application distribution (at the procedure level) It is mature It is well understood It works! 29/29