EmbLogic's Blog

Socket

Socket is an end point communication between two systems on a network. Socket is a combination of IP address an port on one system.

socket(int domain, int type, int protocol) => creates an unnamed socket inside the kernel and returns an integer known as socket descriptor.

1st arg. – takes domain/family for internet family of IPv4 addresses. we use AF_INET.

2nd arg. – they are of two types -

SOCK_STREAM

SOCK_DGRAM

3rd arg. – generally left ’0′. to let the kernel decides the default protocol to use for this connection.

Various system calls used in socket() are :

bind(int sockfd, const struct sockaddr *addr,  socklen_t addrlen);

listen(int sockfd, int backlog);

connect(int sockfd, const struct sockaddr *addr,  socklen_t addrlen);

accept(int sockfd, const struct sockaddr *addr,  socklen_t addrlen);

bind(), connect() and accept() are same but there is a difference i.e. :

bind() and connect() have server sockfd and server address

accept() have server sockfd and client address

 

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>