c - socket connect() vs bind() -


both connect() , bind() system calls 'associate' socket file descriptor address (typically ip/port combination). prototypes like:-

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

and

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

what exact difference between 2 calls? when should 1 use connect() , when bind()?

specifically, in sample server client codes, found client using connect() , server using bind() call. reason not clear me.

to make understanding better , lets find out bind , connect comes picture,

further positioning of 2 calls , clarified sourav,

bind() associates socket local address [that's why server side binds, clients can use address connect server.] connect() used connect remote [server] address, that's why client side, connect [read as: connect server] used.

we cannot use them interchangeably (even when have client/server on same machine) because of specific roles , corresponding implementation.

i further recommend correlate these calls tcp/ip handshake .

enter image description here

so , send syn here , connect() . while bind() used defining communication end point.

hope helps!!


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -