26
1 Sub-Topic : Functions of Ports & Sockets

Ports & sockets

Embed Size (px)

DESCRIPTION

ppt's for Ports and sockets

Citation preview

Page 1: Ports  & sockets

1

Sub-Topic : Functions of Ports & Sockets

Page 2: Ports  & sockets

Recap

In the previous topic , you have learnt about

• Features of TCP/IP

2

Page 3: Ports  & sockets

3

Objectives

On completion of this topic, you will be able to know about

• Purpose of Ports and Sockets

• Define Ports and port numbers

• Define sockets and socket numbers

• Functions of ports and sockets

• Explain the functions of Ports and Sockets

Page 4: Ports  & sockets

4

Ports and Sockets

• A Client machine is capable of browsing multiple web pages originated from different web servers simultaneously

• Ports and Sockets help to identify the process running on the host machine uniquely

• Every process is identified by a 16-bit port number• Socket is the program that is associated with every

process• When a web page is opened, automatically a socket

program is initialized to receive/send packets to the process

• A port number is also created to identify the process uniquely

Page 5: Ports  & sockets

5

Ports and Sockets

• The socket program at source communicate with the socket program at the destination machine with the associated source port/destination port numbers

• When a web page is terminated automatically, the socket programs will be terminated and the associated port numbers are released back

Page 6: Ports  & sockets

6

Why need Ports & Sockets ?

• Client machines run multiple processes while browsing multiple web pages at the same time

Example : Computer A communicate Computer C using

TELNET

Computer A communicate Computer B using FTP

• To communicate over TCP, the source process and destination process establish a connection to one another

• Every TCP connection can be uniquely identified by its two endpoints

Page 7: Ports  & sockets

7

• Data transfer from source to destination host needs IP Address and Physical Addresses of Connection End Points

• Ports and Sockets are Connection End Points

• Each process binds a socket to its end of the connection

• The source and destination each reads from and writes to the socket bound to the connection

• TCP multiplexes multiple connections to a single Internet host using Ports and Sockets

Why need Ports & Sockets ? Contd…

Page 8: Ports  & sockets

8

What is a Port ?

• One of the circuit connection points on a front end processor or local intelligent controller

• The TCP and UDP protocols use ports to map incoming data to a particular process running on a computer

Dest.

Host

Port

SRC

Host

TCP

Page 9: Ports  & sockets

9

Ports

TCP or UDP

Port Port Port Port

Process 1 Process 2 Process 3 Process 4

Port# Data

Data

Packet• At the transport layer, an address is needed to choose among multiple

processes running on the destination host called Port Number

• Destination Port Number for delivery

• Source Port Number for reply

Page 10: Ports  & sockets

10

Port Number

• Port is represented by a positive (16-bit ) integer value between 0 and 65,535

• Some ports have been reserved to support common / well known services

• ftp 21/tcp• telnet 23/tcp• smtp 25/tcp• login 513/tcp

• User level process/services generally use port number value >= 1024

Page 11: Ports  & sockets

11

Port Number

• IANA ( Internet Assigned Number Authority ) has divided Port Numbers in to three ranges

• Well – Known Ports

– Ranges from 0 to 1023

– Assigned and controlled by IANA

Page 12: Ports  & sockets

• Registered Ports

– Ranges from 1024 to 49,151

– Not assigned and controlled, but registered by IANA

• Dynamic Ports

– Ranges from 49,152 to 65,535

– Nether registered nor controlled by IANA

– Used by any process temporarily 12

Port Number

Page 13: Ports  & sockets

13

What is a Socket ?

• A Socket is one endpoint of a two-way communication link between two processes 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

• TCP connection can be uniquely identified by its two endpoints, multiple connections are possible between host and the server

• Sockets provide an interface for programming networks at the transport layer

Page 14: Ports  & sockets

14

Socket Address

• Process to Process delivery of data needs two identifiers, IP Address and Port Number at each endpoint

• Socket Address combination of IP address and a Port number

200.23.56.8 69

200.23.56.8 69

<-- Port NumberI P Address

Socket Address

Example

Page 15: Ports  & sockets

15

• Transport Layer Protocol needs a pair of Socket addresses– Client Socket Address

Uniquely defines the Client Process– Server Socket Address

Uniquely defines Server Process

• Both Socket Addresses contain IP Header and

Transport Layer Protocol Header

– IP Header contains IP Addresses

– TCP & UDP Header contains the Port Numbers

Socket Address Contd

Page 16: Ports  & sockets

16

Socket Communication

• A server (program) runs on a specific computer and has a socket that is bound to a specific port. The server waits and listens to the socket for a client to make a connection request

• The client makes a connection request knowing the hostname and port Number on which the server is listening. The client binds to its local port number that it will use during this connection

FIG .1

Page 17: Ports  & sockets

17

• If connection is established, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client

• It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client

FIG .2

Socket Communication Contd….

Page 18: Ports  & sockets

18

• If the connection is accepted by the Client, a socket is successfully created and the client can use the socket to communicate with the server

• The client and server can now communicate by using their sockets

Socket Communication contd….

Page 19: Ports  & sockets

19

Types of Sockets

Active Socket

• Connected to a remote active socket via an open data connection

• Closing the connection, destroys the active sockets at each point

Passive Socket

• Connected, but awaits an incoming connection, which will spawn a new active socket

Each port contains

• Single Passive Socket - awaiting incoming connections

• Multiple Active Sockets - each corresponds to an open connection on the port

Page 20: Ports  & sockets

20

Summary

In this topic , you have learnt about

• Every TCP connection can be uniquely identified by its two endpoints

• TCP multiplexes multiple connections to a single Internet host using Ports and Socket

• The TCP and UDP protocols use ports to map incoming data to a particular process running on a computer

• Port is represented by a positive (16-bit ) integer value between 0 and 65,535

Page 21: Ports  & sockets

21

Summary

• A Socket is one endpoint of a two-way communication link between two processes running on the network

• Sockets provide an interface for programming networks at the transport layer

• Socket Address is the combination of IP address and Port number

• Network devices communicate with each other by establishing a connection and their sockets bound to the local ports

Page 22: Ports  & sockets

22

Quiz

1. Transport layer protocols use ____ to map incoming data to a process

A. Ports

B. Sockets

C. Packets

D. All of the above

Page 23: Ports  & sockets

23

Quiz

2. A Port Number ranges from ____________

A. 1024 to 65536

B. 0 to 65535

C. 0 to 1024

D. 4096 to 65535

Page 24: Ports  & sockets

24

Quiz

3. Socket Number is a combination of ________

A. Segment Number, Port Number

B. IP Address, Port Number

C. Net ID, IP Address

D. All of the above24

Page 25: Ports  & sockets

25

Quiz

4. Sockets provide an interface for programming networks at the ____________ layer

A. Application

B. Network

C. Physical

D. Transport

Page 26: Ports  & sockets

26

Frequently Asked Questions

1. What is the need of ports and sockets ?

2. What is a Port and Port Number ?

3. List the various ranges of port numbers and their purpose

4. What is a socket and socket number ?

5. What are the functions of ports and sockets ?

6. List the types of sockets

7. Explain how client and server communicate ?