文章目录1.基本TCP客户/服务器程序的套接字函数2.socket函数3.bind函数4.listen函数5.connect函数6.accept函数7.close函数1.基本TCP客户/服务器程序的套接字函数2.socket函数 #include<sys/socket.h> int socket(int family, int type, int protocol); //...
#include<sys/socket.h>
int socket(int family, int type, int protocol);
//return 0 when success ,otherwise -1
listenFd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
socket函数创建一个未绑定ip和端口的套接字。
3.bind函数
#include<sys/socket.h>
int bind(int sockfd, const struct sockaddr* myaddr, socklen_t *addrlen);
//return 0 when success ,otherwise -1
bind函数将套接字绑定到指定的地址myaddr上
4.listen函数
#include<sys/socket.h>
int listen(int sockfd, int backlog);
//return 0 when success ,otherwise -1
文章目录1.基本TCP客户/服务器程序的套接字函数2.socket函数3.bind函数4.listen函数5.connect函数6.accept函数7.close函数1.基本TCP客户/服务器程序的套接字函数2.socket函数 #include<sys/socket.h> int socket(int family, int type, int protocol); //...