头文件
#include <sys/socket.h> //函数和数据结构定义在这个头文件
#include <netinet/in.h> //IPv4和IPv6相关协议族需要的信息
#include <sys/un.h> //UNIX机器间通信的相关信息
#include <arpa/inet.h> //处理数字从操作系统字节序到网络字节序
#include <netdb.h> //映射服务到IP地址
API函数
socket() //创建socket(套接字)
bind() //绑定socket到IP地址和端口
listen() //服务器监听客户端的连接
connect() //客户端连接到服务器
accept() //应用程序接受完成3次握手的客户端连接
send() //发数据
recv() //接受数据
write() //写数据
read() //读数据
close() //关闭socket
gethostbyname() gethostbyaddr() //v4专有
select() poll() //处理多个连接的读,写和错误状态(一般不用,效率低)
getsockopt() //得到对应socket的选项值
setsockopt() //设置对应socket的选项值