Introduction of Socket

  • The concept of Socket began with the ARPANET in 1971.
  • The term network socket is most commonly used in the context of the Internet protocol suite and is therefore often also called Internet socket.
  • The term network socket is analogous to an electrical device’s female connector.
  • The concept of the socket is described by the transport layer of the TCP/IP protocol suite or the Session layer of the OSI model
  • Network sockets are essential for communication between devices over a network.

Definition of Socket

  • socket is an endpoint of a two-way communication link between two programs for sending or receiving data across a network using different protocols.
  • Socket is an identifier/logical structure to establish a connection between two end machines in a computer network, for complete communication.
  • A network socket is a software structure within a network node(Client and Server or host machine) of a computer network that serves as an endpoint for sending and receiving data across the network. 

Characteristics/Features of Socket

  • Each type of socket is designed for a specific type of communication and use case, allowing developers to choose the appropriate socket type based on the requirements of their application.
  • The socket is responsible for the process-to-process delivery of messages in a network between the sender and receiver.
  • A socket is bound to a unique port number so that the TCP/IP protocol suites can identify the different applications data is destined to be sent.
  • Network sockets dedicate the persistent connections for communication between two nodes in a network.
  • Sockets are created only during the lifetime of a process of an application running in the node.
  • In the client-server model, a pair of sockets is required for complete communication i.e. one for the client (client IP address & client port number) and another for the server (server IP address & server port number).
  • The structure and properties of a socket are defined by an application programming interface(API) for the networking architecture.

Structure of Socket

  • A socket is externally identified to other hosts by its socket address, which is created with the API as the triad combination of transport layer protocol(TCP or UDP, used for transmissions)IP or network address of the host machine, and Port number/address of the process running on it. 
  • For example, Suppose the IP address of the machine is 254.200.27.46 and a process running on it is assigned a port number of 2231, then the socket contains (254.200.27.46, 2231). Thus, a socket uniquely identifies the process from the set of processes running on this machine.
  • The combination of client or local socket and remote socket are called socket pairs. Each socket pair is described by a unique 4-tuple consisting of protocols, source, and destination IP addresses, and port numbers

Types of Socket

There are several types of network sockets based on their communication protocols and the way they handle connections.

There are following types of Sockets exist in a network environment- 

(A) Based on the use of protocols in the socket during communication, they are categorized into two parts –

(a) Datagram Socket :

      • This socket uses UDP protocol during communication which is a connectionless method of transmission hence it is also called a Connectionless socket/UDP Socket. 
      • In the datagram socket, each data packet sent or received is individually addressed and routed. The communication order and reliability are not guaranteed, so multiple data packets sent from one machine or process to another may arrive in any order or might not arrive at all.
      • In this socket, special configuration may be required to send data as broadcast way. To receive broadcast packets, a datagram socket may or may not be bound to a specific address due to a connectionless feature.
      • UDP sockets are not identified by the remote address, but only by the local address, although each message has an associated remote address that can be retrieved from each datagram with the networking application programming interface (API).
      • Unlike TCP sockets, UDP sockets do not have an established state, because it uses the connectionless protocol.

(b) Stream Socket :

      • This socket uses TCP protocol during communication which is a connection-oriented method of transmission hence it is also called Connection Oriented socket/TCP Socket. 
      • A stream socket provides a sequenced and unique flow of error-free data without record boundaries, with well-defined mechanisms for creating and destroying connections and reporting errors.
      • A stream socket transmits data reliably, in order, and with out-of-band capabilities.

(B) Based on the way they handle connections, they are categorized into the following parts –

(a) Raw Socket

      • Raw sockets allow direct sending and receiving of IP packets without protocol-specific transport layer formatting. For this, Raw sockets bypass normal transport protocols (TCP/UDP), allowing direct access to the network hardware.
      • Raw sockets are typically available in network equipment and used for routing protocols such as IGRP, OSPF, and ICMP.
      • This socket is mainly used by programs that require direct interaction with the network layer, such as network diagnostic tools (e.g., ping, traceroute) or custom protocol implementations.
      • It requires administrative privileges.
      • It is used for network monitoring, security testing, or protocol development.

(b) Bluetooth Socket

      • This socket uses L2CAP (Logical Link Control and Adaptation Protocol) or RFCOMM protocol.
      • This socket is used for wireless communication between Bluetooth-enabled devices.
      • In this socket, different protocols (L2CAP, RFCOMM) offer varying levels of abstraction, from low-level data transmission to higher-level serial data transfer, respectively.

(c) Sequenced Packet Sockets (SOCK_SEQPACKET)

      • It can use protocols like SCTP (Stream Control Transmission Protocol)
      • It is similar to stream sockets, but data is transmitted in fixed-length, reliable, and sequenced packets.
      • This socket is connection-oriented and ensures data integrity, like TCP, but the data is processed as a series of independent messages rather than a continuous stream.
      • This socket is typically used in scenarios requiring reliable, message-based communication, such as telecommunications signaling.

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.