connect()
和bind()
系统调用都将套接字文件描述符与地址(通常是ip/端口组合)关联起来.他们的原型如下:-
int connect(int sockfd, const struct sockaddr *addr,
socklen_t addrlen);
和
int bind(int sockfd, const struct sockaddr *addr,
socklen_t addrlen);
What is the exact difference between 2 calls? When should one use connect()
和 when bind()
?
Specifically, in some sample server client codes, found that client is using connect()
和 server is using the bind()
call. Reason was not fully clear to me.