Socket is a communication mechanism between two process.These process could be in the same system or different system.It is also known as end point of networking.
Socket provide interfacing between the network and the application on the system.Socket is very similar to the pipe,But PIPE has file descriptor on both side,whereas Socket has file descriptor on one end and Network interface on the other side.Socket file descriptor can not be shared with other process.Also,Pipe is used to provide communication between the two process on the same system.
There are two types of Socket:
1.SOCK_STREAM:
*It is reliable.
*Connection oriented.
*Guarantee data transfer.
*Maximum data transfer.
2.SOCK_DGRAM:
*Not reliable.
*Connectionless.
*Short data transfer.
*Data may be lost.
Various system call used in socket are:
int socket(int domain,int type,int protocol);
int bind(int sockfd,(struct sockaddr *)&addr,size_t addr_len);
int listen(int sockfd,int backlog);
int accept(int sockfd,struct sockaddr *addr,size_t *addrlen);
int connect(int sockfd,struct sockaddr *addr,size_t addr_len);