Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

@aribzzter_

Socket vs Port – Detailed Explanation and


Difference

What is Socket Port?

A socket port is one endpoint in a statement flow in the middle of two programs
running over a network, also it is maintaining and allow communication between two
different processes on the same or different machines. socket address is the
combination of an IP address and a port number.
Related – IP Address vs Port Number
In networking, a socket is used to allow many processes within a single or different host
to use TCP communication simultaneously.
The socket is formed by including the IP address with the port number to uniquely
identify each separate data stream. A connection can be fully specified by the sockets
at each end.
Also, we call socket as a type of a ‘tag’, that individually identifies and keeps a
connection, such that request and reply are sent & received by the correctly mapped
application running on a device.

Socket arrange for an interface for programming networks at the transport layer.

TYPE OF SOCKETS
Active Socket
Associated to a remote active socket through an open data connection.
Closing the association terminates the active sockets at each point.
Passive Socket
Associated, but awaits an incoming connection, which will brood a new active socket.

For more clarity, let’s take an example – Think of your machine as an apartment building –
▪ A port is an apartment number.
▪ A socket is the door of an apartment.
▪ An IP address is the street address of the building.
Some of the commonality between port number and Socket is shared below –
▪ Ports and sockets help identify process running on host machine uniquely.
▪ When a web page is terminated automatically, the socket programs will be
terminated and associated port numbers are released back.
What is Port Socket?
In the Internet Protocol Suite, a port socket is an endpoint of communication in an
operating system. in software, it is a rational construct that classifies a particular
process or a sort of network service.
And it is permanently related with an IP address of a host and the protocol type of the
statement, and thus finalizes the destination or origination network address of a
communication session.
Port is called as a service delivered by a machine and each and every service running
with a particular or customized port (The service is recognized by a port number).
There are a lot of consistent port numbers for general services.

TCP and UDP use ports to map inward data to an individual process on a computer.

PORTS NUMBER
Ports are signified by optimistic (16-bit) numeral value between 0 and 65535

The port numbers are allocated into three ranges

▪ Well Known Ports 0 to 1023. Assigned & controlled by IANA.


▪ Registered Ports, 1024 to 49151. Not assigned & controlled by IANA. But
registered by IANA.
▪ Dynamic and/or Private Ports, 49152 to 65535.Not assigned & registered by IANA
Some ports have been kept to provision shared / well-known service.

▪ FTP 21/tcp
▪ Telnet 23/tcp
▪ SMTP 25/tcp
▪ SSH 22/tcp

Comparison table: Socket vs Port

Types of Sockets in Computer Networks

In computer networks, there are several types of sockets that are used to establish
communication between devices.

ACTIVE SOCKETS
Active sockets, also known as open sockets, are a type of socket that is actively
being used for communication between two devices. When an application creates
a socket and establishes a connection with another device, the socket becomes
active and remains open until the connection is terminated. Active sockets are
used for bidirectional communication, allowing data to be sent and received in
both directions between the two devices. They are identified by a unique
combination of IP address and port number, which ensures that data is
transmitted to the correct endpoint. Active sockets are an essential component of
network communication, enabling applications to communicate with each other
over the Internet or other network.

PASSIVE SOCKETS

Passive sockets, also known as listening sockets, are a type of socket that listens
for incoming connections from other devices. When an application creates a
passive socket, it waits for connection requests from other devices, but does not
actively transmit data until a connection is established. Passive sockets are used to
accept incoming connections, allowing devices to initiate communication with the
application. They are identified by a unique combination of IP address and port
number, which allows them to listen for incoming connections on a specific
endpoint. Passive sockets are an essential component of server applications,
allowing them to accept incoming connections from client applications and
respond to requests for data or services.

INTERNET SOCKETS
Internet sockets are a mechanism used in computer networks to establish
communication between devices over the Internet using the TCP/IP protocol suite.
They allow applications to communicate with each other by creating endpoints for
data transmission. Internet sockets are identified by an IP address and a port
number, which uniquely identify the endpoint for data transmission. One
endpoint is created by the client application, and the other is created by the
server application. Internet sockets are commonly used to establish connections
for a variety of purposes, such as sending and receiving data, streaming audio and
video, and remote control of devices. They provide a flexible and efficient way for
applications to communicate with each other over the Internet, enabling the
development of a wide range of networked applications and services.
UNIX SOCKETS
Unix sockets are a mechanism used in Unix-like operating systems for inter-
process communication between processes running on the same machine. They
use a special file system called the Unix domain sockets (UDS) to enable
communication between processes as if they were communicating over a network
socket. Unix sockets are faster and more efficient than Internet sockets because
they do not require network overhead. They are commonly used for local inter-
process communication, such as between a web server and a database server or
between different components of an application running on the same machine.
Unix sockets provide a simple and efficient way for processes to communicate
with each other without the need for complex network configurations.

DATAGRAM SOCKETS
Datagram sockets are a type of socket used for connectionless communication
between devices in computer networks. They are used in protocols such as User
Datagram Protocol (UDP), where each packet of data is handled independently
and without any prior knowledge of the packets that come before or after it.
Datagram sockets do not require a connection to be established before data can
be transmitted, making them faster and more efficient than other types of
sockets. They are commonly used for applications that require real-time data
transmission, such as online gaming or video streaming, where speed and
efficiency are critical.

RAW SOCKETS
Raw sockets are a type of socket that allow applications to send and receive data
at the network layer of the TCP/IP protocol suite. Unlike other types of sockets,
raw sockets bypass the transport layer protocols such as TCP or UDP and
communicate directly with the network layer. This gives applications complete
control over the packet structure, including the ability to modify fields such as the
source and destination IP addresses. Raw sockets are commonly used for tasks
such as network scanning, packet filtering, and protocol development and testing.
They provide a powerful and flexible way for applications to interact with the
network layer, but also require a higher level of expertise and responsibility from
the application developer due to the potential security risks involved.

MULTICAST SOCKETS
A multicast socket is a type of socket used in computer networks for sending data
to multiple destinations simultaneously. It allows a single sender to send data to
multiple recipients who have expressed interest in receiving that data, reducing
network traffic and improving efficiency. Multicast sockets use the Internet Group
Management Protocol (IGMP) to manage group membership and determine
which devices receive the data. They are commonly used for applications such as
streaming media, online gaming, and real-time data distribution, where it is
necessary to transmit data to a large number of recipients simultaneously.
Multicast sockets provide an efficient and scalable way to distribute data to
multiple devices on a network.

BLUETOOTH SOCKETS
A Bluetooth socket is a type of socket used in wireless communication between
Bluetooth-enabled devices. It allows for a reliable and secure connection between
two devices over short distances without the need for cables or wires. Bluetooth
sockets use the Bluetooth protocol stack, which includes layers for radio
frequency (RF) communication, data transmission, and application layer services.
They are commonly used for a variety of applications, including wireless audio
streaming, file sharing, and remote control of devices. Bluetooth sockets provide a
convenient and efficient way for devices to communicate with each other without
the need for physical connections, making them ideal for use in portable and
mobile devices.

NFC SOCKETS
NFC (Near Field Communication) sockets are a type of socket used in wireless
communication between NFC-enabled devices. They allow for the exchange of
data between two devices when they are held close together, typically within a
few centimeters. NFC sockets use electromagnetic induction to transmit data
between devices, and are commonly used for contactless payment systems,
access control, and other applications that require secure and convenient data
transfer. NFC sockets are considered to be highly secure, as they require close
proximity for data transfer and use encryption protocols to protect against
unauthorized access. They provide a fast and convenient way for devices to
communicate with each other without the need for physical connections, making
them ideal for use in mobile devices such as smartphones and tablets.
Types of ports In computer networks…

In computer networks, there are several types of ports that are used for
communication between devices. Some of the commonly used ports are:

1. TCP ports: Transmission Control Protocol (TCP) ports are used for reliable,
connection-oriented communication between devices. They are used for
protocols like HTTP (port 80), HTTPS (port 443), FTP (port 21), SSH (port 22),
Telnet (port 23), and many others.

2. UDP ports: User Datagram Protocol (UDP) ports are used for connectionless
communication between devices. They are used for protocols like DNS (port 53),
DHCP (port 67/68), SNMP (port 161/162), and others.

3. Well-known ports: These are the ports that are reserved for specific
applications and services. For example, port 80 is reserved for HTTP traffic, port
443 is reserved for HTTPS traffic, and port 22 is reserved for SSH traffic.

4. Registered ports: These are the ports that are registered with the Internet
Assigned Numbers Authority (IANA) and are available for use by applications and
services. They range from 1024 to 49151.

5. Dynamic or private ports: These are the ports that are used by client
applications to initiate communication with servers. They range from 49152 to
65535.

It's worth noting that ports are identified by a number between 0 and 65535. In
TCP and UDP, each port number represents a unique endpoint for communication.

In short……….
In networking, a port is a virtual endpoint for communication between processes
or services on a networked device. A socket, on the other hand, is a combination
of an IP address and a port number that uniquely identifies a connection endpoint
in a network.
When a process on a device wants to communicate with a process on another
device, it sends data through a port, which is associated with a specific protocol.
For example, HTTP uses port 80 by default, while HTTPS uses port 443.

Sockets are used to establish and manage connections between devices. When a
process on a device wants to establish a connection with a process on another
device, it creates a socket by specifying the remote device's IP address and port
number. The socket then provides a channel for data exchange between the two
processes.

In summary, ports and sockets are essential components of network


communication, and they help ensure that data is transmitted correctly and
efficiently between processes and devices on a network.
----------------------------------------------------

You might also like