20

Transport services

Embed Size (px)

Citation preview

Page 1: Transport services
Page 2: Transport services

The Transport LayerThe transport layer is the heart of the

protocol hierarchy. The network layer provides end-to-end

packet delivery using datagrams or virtual circuits.

The transport layer builds on the network layer to provide data transport from a process on a source machine to a process on a destination machine with a desired level of reliability

Page 3: Transport services

The Transport Service•Services Provided to the Upper

Layers•Transport Service Primitives•Berkeley Sockets•An Example of Socket

Programming: An Internet File Server

Page 4: Transport services

Services Provided to the Upper Layers

The ultimate goal of the transport layer is to provide efficient, reliable, and cost-effective data transmission service to its users, normally processes in the application layer.

To achieve this, the transport layer makes use of the services provided by the network layer. The software and/or hardware within the transport layer that does the work is called the transport entity

Page 5: Transport services

Services Provided to the Upper LayersThe (logical) relationship of the network,

transport, and application layers .

Page 6: Transport services

Transport Service PrimitivesTo allow users to access the transport

service, the transport layer must provide some operations to application programs, that is, a transport service interface.

Each transport service has its own interface. This transport interface is truly bare bones,

but it gives the essential flavor of what a connection-oriented transport interface has to do. It allows application programs to establish, use, and then release connections, which is sufficient for many applications

Page 7: Transport services

Transport Service Primitives the purpose of the transport layer—to provide a

reliable service on top of an unreliable networkTo get an idea of what a transport service might

be like, consider the five primitives . To start with, the server executes a LISTEN

primitive, typically by calling a library procedure that makes a system call that blocks the server until a client turns up. When a client wants to talk to the server, it executes a CONNECT primitive.

The transport entity carries out this primitive by blocking the caller and sending a packet to the server.

Page 8: Transport services

Transport Service Primitives

The primitives for a simple transport service.

Page 9: Transport services

Transport Service Primitives the term segment for messages sent from transport

entity to transport entity. TCP, UDP and other Internet protocols use this term.

Thus, segments (exchanged by the transport layer) are contained in packets (exchanged by the network layer).

In turn, these packets are contained in frames (exchanged by the data link layer). When a frame arrives, the data link layer processes the frame header and, if the destination address matches for local delivery, passes the contents of the frame payload field up to the network entity.

The network entity similarly processes the packet header and then passes the contents of the packet payload up to the transport entity

Page 10: Transport services

Transport Service Primitives (3)The nesting of TPDUs, packets, and frames.

Page 11: Transport services

Transport Service Primitives (2)

A state diagram for a simple connection management scheme. Transitions labeled in italics are caused by packet arrivals. The solid lines show the client's state sequence. The dashed lines show the server's state sequence.

Page 12: Transport services

Berkeley Sockets This is another set of transport primitives, the

socket primitives as they are used for TCP. Sockets were first released as part of the

Berkeley UNIX 4.2BSD software distribution in 1983.

The primitives are now widely used for Internet programming on many operating systems, especially UNIX-based systems, and there is a socket-style API for Windows called ‘‘winsock.’’ it is  used for inter-process communication (IPC)

Page 13: Transport services

Berkeley Socketssocket() creates a new socket of a certain socket type,

identified by an integer number, and allocates system resources to it.

bind() is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address.

listen() is used on the server side, and causes a bound TCP socket to enter listening state.

accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.

 This is a methods provided by the Berkeley sockets API library:

Page 14: Transport services

Berkeley Socketsconnect() is used on the client side, and

assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection.

send() and recv(), or write() and read(), or sendto() and recvfrom(), are used for sending and receiving data to/from a remote socket.

close() causes the system to release resources allocated to a socket. In case of TCP, the connection is terminated.

Page 15: Transport services

Berkeley SocketsThe first four primitives in the list are executed in

that order by servers. The SOCKET primitive creates a new endpoint and allocates table space for it within the transport entity.

The parameters of the call specify the addressing format to be used, the type of service desired and the protocol. A successful SOCKET call returns an ordinary file descriptor for use in succeeding calls, the same way an OPEN call on a file does.

Newly created sockets do not have network addresses. These are assigned using the BIND primitive.

Once a server has bound an address to a socket, remote clients can connect to it.

Page 16: Transport services

Socket Programming Example:Internet File Server

Client code using sockets.

6-6-1

Page 17: Transport services

Client code using socketimport java.net.*; import java.io.*; class MyClient{ public static void main(String args[])throws Exception{ Socket s=new Socket("localhost",6666); DataInputStream din=new DataInputStream(s.getInputStream()); DataOutputStream dout=new DataOutputStream(s.getOutputStream()); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str="",str2="",str3=""; while(!str.equals("stop")){ str=br.readLine();dout.writeUTF(str);str3=br.readLine() ; dout.writeUTF(str3); dout.flush(); str2=din.readUTF(); System.out.println("Server says: "+str2); } dout.close(); s.close(); }}

Page 18: Transport services

Socket Programming Example:Internet File Server (2)

Client code using sockets.

Page 19: Transport services

Server code using socket import java.net.*; import java.io.*; class MyServer{ public static void main(String args[])throws Exception{ ServerSocket ss=new ServerSocket(6666); Socket s=ss.accept(); DataInputStream din=new DataInputStream(s.getInputStream()); DataOutputStream dout=new DataOutputStream(s.getOutputStream()); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str="",str2=""; while(!str.equals("stop")){ str=din.readUTF(); System.out.println("client says: "+str); str2=br.readLine(); dout.writeUTF(str2); dout.flush(); } din.close(); s.close(); ss.close(); }}

Page 20: Transport services

Thanks

Presented by:Navin Kumar