what is socket?

Sockets


A socket is an abstraction for network communication, just as a file is an abstraction for file system communication. The interface that resulted from the task that is assigned by Advanced Research Group Projects Agency (ARPA) to a group at the University of California, Berkeley , to port TCP/IP software to the UNIX operating system become known as the socket interface sometimes Berkeley socket interface. The Berkeley socket interface extends the concept of a file descriptor to that of socket descriptor. A socket structure contains information such as socket type,port being used by socket, local address, and the remote address and port that will
receive communication from the socket. Sockets can be used in two different ways, once we create a socket it can wait for the connection, or it can initiate a connection to another remote host or its own local host. A socket used by client program to initiate a connection to the server called active socket. While the socket that acts as a server and wait for the connection is known as passive client.


Types of Sockets

(a). Stream Sockets
(i). These sockets use TCP (Transmission Control Protocol),which is a reliable, stream oriented protocol where streams are used for input and output data.

(ii). The client creates a TCP socket by specifying the server’s IP address and port number of the server process.

(III. )When client creates a TCP socket it establishes a passive connection with the server TCP.

(iv). Server TCP creates a new TCP connection for each client that requests a communication so that it can handle the communication with multiple clients at the same time.

(v). Once a client server control connection is created, data can be transferred as long as that control connection is active.

(b). Datagram sockets
(i). These sockets use UDP (Unix Datagram Protocol), which is unreliable and message oriented where datagrams are used for input and output data.

(ii). No handshaking is done with UDP sockets since the client explicitly attaches IP address and port of destination (i.e. server).

(III).Transmitted data may be received out of order or lost completely.

(iv). This type of packet can be sent at any time to the destination.

(v)Since they are connectionless, therefore they are not globally unique.

(vi)These are generally smaller than TCP sockets.

(c). Raw IP sockets
(i). These types of sockets are used to create raw IP Packets bypassing the transport layer.

(ii). The type SOCK_RAW is used when socket() is called.

(iii). The packet is directly passed to the application that needs it without making it to go through the whole encapsulation/ decapsulation process.

(iv). The headers are made by the process retrieving the data from the sockets rather than the complex TCP/IP mechanism.

(v). These are not used in java.


Share this post and spread the knowledge --->

No comments:

Post a Comment