Netdevops by Reza

Infrastructure Eng & Veteran Network Eng | Certified CCNP Enterprise & MCSE | Focused on Agile Leadership and DevOps

What are the Sockets


A socket is one endpoint of a two way communication link between two programs running on the network. The socket mechanism provides a means of inter-process communication (IPC) by establishing named contact points between which the communication take place.

Like ‘Pipe’ is used to create pipes and sockets is created using ‘socket’ system call. The socket provides bidirectional FIFO Communication facility over the network. A socket connecting to the network is created at each end of the communication. Each socket has a specific address. This address is composed of an IP address and a port number.

Socket are generally employed in client server applications. The server creates a socket, attaches it to a network port addresses then waits for the client to contact it. The client creates a socket and then attempts to connect to the server socket. When the connection is established, transfer of data takes place.

Socket Types:

Stream Sockets − Delivery in a networked environment is guaranteed. If you send through the stream socket three items “A, B, C”, they will arrive in the same order − “A, B, C”. These sockets use TCP (Transmission Control Protocol) for data transmission. If delivery is impossible, the sender receives an error indicator. Data records do not have any boundaries.

Datagram Sockets − Delivery in a networked environment is not guaranteed. They’re connectionless because you don’t need to have an open connection as in Stream Sockets − you build a packet with the destination information and send it out. They use UDP (User Datagram Protocol).

Raw Sockets − These provide users access to the underlying communication protocols, which support socket abstractions. These sockets are normally datagram oriented, though their exact characteristics are dependent on the interface provided by the protocol. Raw sockets are not intended for the general user; they have been provided mainly for those interested in developing new communication protocols, or for gaining access to some of the more cryptic facilities of an existing protocol.

Sequenced Packet Sockets − They are similar to a stream socket, with the exception that record boundaries are preserved. This interface is provided only as a part of the Network Systems (NS) socket abstraction and is very important in most serious NS applications. Sequenced-packet sockets allow the user to manipulate the Sequence Packet Protocol (SPP) or Internet Datagram Protocol (IDP) headers on a packet or a group of packets, either by writing a prototype header along with whatever data is to be sent or by specifying a default header to be used with all outgoing data and allows the user to receive the headers on incoming packets.

What Is a Port?

Port is a part of the transport layer and helps in network communication. A port is a logical identifier assigned to a process in order to identify that process uniquely in a network system. When two network devices communicate, they do so by sending packets to each other. Each packet received by a receiver device contains a port number that uniquely identifies the process where the packet needs to be sent.

Not all the network protocol uses a port for communication. For example, ICMP doesn’t use a port. On the other hand, protocols like TCP, UDP, HTTP utilize a port for communication.

Let’s look at an example. A client computer is requesting the server for a virtual connection with the port number 23. Telnet is a well-known protocol for establishing a remote connection over a TCP/IP and it uses port 23. Hence, the server acknowledges the request from the client and start a telnet connection.

Port vs. Socket



  1. GeeksForGeeks
  2. Baeldung
  3. tutorialspoint