c语言socket通信包含以下几个最常用的函数。根据使用方(客户端或服务端)有不同的调用方法,简单示图如下:
1、socket()
要建立一个网络连接,不论客户端或服务端首先都要调用socket()函数建立一个网络通信的套接口:
#include<sys/types.h>
#include<sys/socket.h>
int socket(int domain, int type, int protocol);
第一个参数domain为网络通信的协议族,使用ipv4则设为AF_INET,ipv6则设为AF_INET6。
第