数据传输三要素:源、目的、长度;
(使用“IP+端口”表示源/目的)
服务器server:被动的响应请求
客户端client:主动的发起请求
网络通信方式:TCP/UDP
TCP
服务器server 客户端client 1、使用socket打开:
int socket(int domain, int type, int protocol)
1、使用socket打开:
int socket(int domain, int type, int protocol)
2、为能够响应请求得不断监测端口:bind(IP+端口) 3、启动监测数据:listen 4、建立并接受连接:accept 2、发起并建立连接:connect(IP+端口) 5、处理数据:收recv 发send 3、处理数据:收recv 发send 示意图如下:
UDP
服务器server 客户端client 1、使用socket打开:
int socket(int domain, int type, int protocol)
1、使用socket打开:
int socket(int domain, int type, int protocol)
2、为能够响应请求得不断监测端口:bind(IP+端口) 2、发起并建立连接:connect(IP+端口)
(虚假连接,只为包含源/目的)
3、处理数据:收recv 发send 3、处理数据:收recv 发send 示意图如下: