Application Layer Protocol
Agenda
What basically are the function of Application Layer?
What are the different types of application around the internet?
Client Server
Peer to Peer
Sockets Vs Port
HTTP
DNS
Application Layer
Responsibilities
- Creates & receives data
Application Architecture
Client-Server Architecture
Client: Laptop from where I access google.com Server: Big servers in Google Data Center
Client is someone who needs to consume the content/information. Server is someone who owns the data. Application on client has a diff purpose than application on server.
P2P Architecture (Peer to Peer Architecture)
Everyone is same.
If the same application is running on every machine of computer, these applications will talk to each other.
Everyone has some data & everyone can give some data.
There is only 1 category of machine.
Ex: Torrent. It's a p2p application.
every machine acts as client & server
Sockets
So as to be able to get the data from a particular port on the current machine, application needs to write some code.
This API of connecting yourself to a particular port/attaching your application to a particular port & ability to send the data from there & receive from there is known as socket programming.
The API that allows applications to send the data over the internet or receive the data from the internet is known as Socket API.
Socket API is actually implemented by OS. A functionality provided by OS.
OS comes with a socket API. Every other programming languages will write a wrapper over this API.
Java also has it's socket API. It is going to be almost 100% similar to OS API, just probably names of a few methods might be different. We use Java's classes for socket's. Same way in other languages too.
Wrapper: Class that behind the scenes calls the methods of wrapped object. Wrapped object is OS API. class is the python API.
Socket API (Usecase)
To bind your application to a particular port.
To send the data (by calling appropriate methods on socket object). Ex: socket.send()
Receive the data. Ex: socket.receive()
Socket is just a class that allows application to bind to a particular port & send & receive data via the port.
Socket is internal to the application. It is just an object of a class. Clients don't know about socket
Client connects to server via a port. Port is an external thing.
Socket has no physical existence.
FLOW Application -> Socket -> OS API -> PORT --> Receiver PORT ->Receiver OS -> Socket Wrapper -> Application
Default port of HTTP is 80.
All the ports of this machine being used : % sudo lsof -i -n -P | grep TCP
Ephimeral Port
- Browser Port Browser creates an ephimeral port. When you create an ephimeral port, a random port is assigned to you.
Whenever you open a new tab in Google Chrome, it creates a socket, binds to an ephimeral port.
Port size is 16 bits. There can be 2 to the power 16 PORTS.
If something has to go over the internet / received over the internet, a socket object has to be created.