Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 26/09/2007.

Similar presentations


Presentation on theme: "Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 26/09/2007."— Presentation transcript:

1 Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering umar.kalim@niit.edu.pk http://www.niit.edu.pk/~umarkalim 26/09/2007

2 Fall 2007cs4252 Agenda Communication ~ Overview Sockets

3 Fall 2007cs4253 Review ~ Distributed Systems DS: Autonomous computers that work together, giving the appearance of a single coherent system –Easy to integrate different applications on different machines into a single system –When properly designed, they scale well Types –Distributed Operating Systems ~ Homogenous platforms, tightly coupled, single system view –Network Operating System ~ Possibly Heterogeneous platforms, loosely coupled, no single system view –Middleware ~ Additional software using NOS, hides heterogeneity and distributed nature, single system view, allows for a variety of distribution models

4 Fall 2007cs4254 Communication Ref: COMP 212, University of Liverpool

5 Fall 2007cs4255 Inter-process communication The “heart” of every distributed system Question: how do processes on different machines exchange information? Answer: with difficulty …  Established computer network facilities are too primitive, resulting in distributed systems that are too difficult to develop – a new model is required

6 Fall 2007cs4256 Clients and Servers Participants are divided into –Servers: implementing a specific service –Clients: requesting a service from a server by sending it a request and subsequent waiting for the server’s reply Distributed across different machines Follow a request-reply

7 Fall 2007cs4257 Lets step back and study how communication between a client and server be implemented in the simplest manner

8 Fall 2007cs4258 Review ~ Layered Protocols Layers, interfaces, and protocols in the OSI model.

9 Fall 2007cs4259 Review ~ Layered Protocols A typical message as it appears on the network.

10 Fall 2007cs42510 Review ~ Physical Layer The physical layer specifies the mechanical, electrical and optical behaviour of the plugs and sockets of a physical interface to the network. Implementations of the physical layer perform functions in order to signal, modulate, and synchronize the transmission of bits over the physical network. It may perform error detection by monitoring the quality of the electrical or optical signals received.

11 Fall 2007cs42511 Review ~ Data Link Layer Responsible for transmission of packets between nodes that are directly connected by a physical link. Nodes may be routers, switchers, or computers. It maps the physical connection provided by the physical layer into a layer that can transmit packets from one node to another in a relatively error-free mode. Provides error correction based on physical error detection primitives provided by the physical layer.

12 Fall 2007cs42512 Review ~ Network Layer While the data layer is concerned with a node- to-node connection, the network layer implements the connection of multiple nodes into a network. It is concerned with routing messages along multiple nodes in the network. It implements connections between arbitrary nodes of the network.

13 Fall 2007cs42513 Review ~ Transport Layer The transport layer adds the capability of mapping longer messages or even continuous sequences of data onto the package-routing capabilities. If network layer does not provide reliable package routing, then transport layer adds such reliability.

14 Fall 2007cs42514 Review ~ Session & Presentation Layer The session layer provides facilities to establish and maintain connections between two or mode distributed components. The presentation layer resolves differences between –high level data structures (eg: records, arrays, sequences, …) –atomic data structures (eg: integers represented as bigendians or little-endians) –…. in the representation of information between distributed components.

15 Fall 2007cs42515 Review ~ Application Layer Contains the protocols that are designed to meet the communication requirements of specific applications, often defining the interface to a service. Examples: HTTP, FTP, CORBA, …

16 Fall 2007cs42516 Connection (-less) Transport Layer Connection-oriented transportation layers –Provide operations to:  Open a connection  Close a connection  Write data into such a connection;  Read data from such a connection. Connection-less transportation layers –Provide the ability of sending fixed length messages between distributed hosts; –These messages are referred as datagrams;

17 Fall 2007cs42517 Internet Transport Protocols Transmission Control Protocol (TCP) –Connection-oriented –Reliable but slow User Datagram Protocol (UDP) –Connection-less –Very fast but unreliable Choice of protocol depends on whether or not the application needs to retain the connection for long periods of time.

18 Fall 2007cs42518 TCP – Graphical Representation

19 Fall 2007cs42519 UDP Graphical Representation

20 Fall 2007cs42520 Communication at Transport Layer Provided by all networks Practically, lowest-level protocol available to application developer Provided in Java

21 Fall 2007cs42521 Sockets and Ports A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.

22 Fall 2007cs42522 Problem: Identifying “end-points”? How do clients know which end-point (or port) to contact a server at? How do they “bind” to a server? 1.Statically assigned end-points (e.g., TCP port 21 for telnet, TCP port 80 for HTTP,…) 2.Dynamically assigned end-points (have a special daemon on each machine that runs servers, a client first contacts the daemon). 3.“Super-server” (listens to several ports, i.e., provides several services. Starts another process/thread).

23 Fall 2007cs42523 Servers: Binding to end-points a)Client-to-server binding using a daemon (DCE). b)Client-to-server binding using a super-server (inetd on UNIX).

24 Fall 2007cs42524 Sockets in Java Facilities for simple network programming in Java can be found in Java.net package Main classes Socket and ServerSocket

25 Fall 2007cs42525 The Socket Class Provides a number of constructors which enable the programmer to create a socket to a remote computer. It is usually for programming clients. The simplest constructor has two arguments: –String (name of the computer using the DNS convention –port number. Example: Socket clientSocket = new Socket(“maggie.niit.edu.pk", 80);

26 Fall 2007cs42526 Reading data from Socket The method getInputStream will obtain an InputStream object attached to the socket which can then be used to read data. Example: Socket clientSocket = new Socket(“maggie.niit.edu.pk", 80); InputStream inputStream = clientSocket.getInputStream();

27 Fall 2007cs42527 Using Buffers Also we can attach a buffer to the InputStream object which can contain data until enough can be sent in an efficient way Example: Socket clientSocket = new Socket(“maggie.niit.edu.pk", 80); InputStream inputStream = clientSocket.getInputStream(); BufferedReader bufferedInputStream = new BufferedReader(new InputStreamReader(inputStream)); String lineRead = bufferedInputStream.readLine();

28 Fall 2007cs42528 Writing to a Socket The method getOutputStream can be used to write data to the socket Example: Socket clientSocket = new Socket(“maggie.niit.edu.pk", 2048); OutputStream outputStream = clientSocket.getOutputStream(); PrintWriter writer = new PrintWriter(outputStream, true);

29 Fall 2007cs42529 Bi-directional connection Socket cSocket = new Socket(“maggie.niit.edu.pk", 80) //Set up the streams associated with the socket BufferedReader bufferedInputStream = new BufferedReader(new InputStreamReader(cSocket.getInputStream())); PrintWriter writer = new PrintWriter(cSocket.getOutputStream(), true); //Send message to server writer.println("Hello"); //Get reply from server String fromServer = bufferedInputStream.readLine(); if(reply.equals("Hello")) //Process the reply else //Carry out some error process

30 Fall 2007cs42530 Server Socket Provides a number of constructors which enable the programmer to create a socket on a server. The simplest is –ServerSocket(int port) This creates a socket on the given port (this machine).

31 Fall 2007cs42531 Accepting Connections The most important method: accept This method suspends the server until a client attempts to connect to it. The method “ accept ” returns the Socket object which can be used to establish a connection with the client that has connected in.

32 Fall 2007cs42532 Server Socket I/O ServerSocket serverSocket = new ServerSocket(2500); // Wait for a connection Socket clientSocket= serverSocket.accept(); // Set up the streams associated with the socket BufferedReader bufferedInputStream = new BufferedReader(new InputStreamReader( clientSocket.getInputStream())); PrintWriter writer = new PrintWriter(clientSocket.getOutputStream(),true); // Read string from client String inputLine = bufferedInputStream.readLine(); if(inputLine.equals("Hello")) writer.println("Connection established"); else writer.println("Connection refused");

33 Fall 2007cs42533 How does it work The server waits for a message from a client. If the string is “Hello”, then “Connection established” is sent to the client, otherwise “Connection refused” is sent to the client.

34 Fall 2007cs42534 Sockets with Java ~ Summary 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 2. Create a client socket using the Socket constructor (and catch the exceptions)

35 Fall 2007cs42535 Sockets with Java ~ Summary 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

36 Fall 2007cs42536 Advantages & Disadvantages Main advantage: –they are perfect if you want to develop application specific 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

37 Fall 2007cs42537 Questions In this simple example we passed strings. How to pass an object? –Serialization (converts any object into a string) How do we know then what is sent across the network? Integer, String, Object,…?

38 Fall 2007cs42538 Application Layering Client-Server Model ~ controversial –Distinction between client and server? Consensus on three levels –User Interface level –Processing level –Data level

39 Fall 2007cs42539 User Interface Level Allows end-users to interact with the application –Simple character-based screen  Keyboard & Screen –Advanced Interfaces using windowing  X-Windows (UNIX) –…

40 Fall 2007cs42540 Processing Level The general organization of an Internet search engine into three different layers

41 Fall 2007cs42541 Data Level Persistent Data Storage Maintains Meta-Data Maintains consistency across different applications

42 Fall 2007cs42542 Client Server (Two-Tiered) Architectures Alternative client-server organizations (a) – (e). 1-29

43 Fall 2007cs42543 Multitiered Architectures An example of a server acting as a client.

44 Fall 2007cs42544 Modern Architectures Vertical Distribution –The different tiers correspond directly with logical organization of the application Horizontal Distribution

45 Fall 2007cs42545 Questions? That’s all for today!


Download ppt "Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 26/09/2007."

Similar presentations


Ads by Google