Open In App

Types of Socket

Last Updated : 27 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

A network that is connected with two devices as a link to execute two-way communication on the network. It receives and sends data to the devices. The socket address is a combination of IP address and port. In the TCP/IP layer, a socket is bound as a port number which can identify whether the data is to be sent to an application or not. The transport layer in the socket is the core mechanism for managing and establishing communication between the devices.

Sockets are used as a communication device or interaction between the client and server. It receives information from the client and sends information to the client and disconnects it after receiving the data. 

Types of Socket:

1. Datagram Sockets: Datagram sockets allow processes to use the User Datagram Protocol (UDP). It is a two-way flow of communication or messages. It can receive messages in a different order from the sending way and also can receive duplicate messages. These sockets are preserved with their boundaries. The socket type of datagram socket is SOCK_DGRAM.

2. Stream Sockets: Stream socket allows processes to use the Transfer Control Protocol (TCP) for communication. A stream socket provides a sequenced, constant or reliable, and two-way (bidirectional) flow of data. After the establishment of connection, data can be read and written to these sockets in a byte stream. The socket type of stream socket is SOCK_STREAM.

3. Raw Sockets: Raw Socket provide user access to the Internet Control Message Protocol (ICMP). Raw sockets are not used for most applications. These sockets are the same as the datagram oriented, their characteristics are dependent on the interfaces. They provided support in developing new communication protocols or for access to more facilities of an existing protocol. Only the superusers can access the Raw Sockets. The socket type of Raw Socket is SOCK_RAW.

4. Sequenced Packet Sockets: Sequenced Packet Sockets are similar to the stream socket, with the exception that record boundaries are preserved in-stream sockets. The given interface in this section is of Network System ( NS) that has an abstraction of Sockets and is ordered in all the applications. The Sequenced Packet Sockets enable the user to multiply the sequence packet protocol or some IDP (Internet Datagram Protocol) which heads on the packet or a packet group by writing in the header of the prototype along with the data that has been sent. The socket type of Sequenced Packet Socket is SOCK_SEQPACKET.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads