tcp communication process
Server: Create streaming socket binding listener extract readwrite close
Client: Create streaming socket connection read-write closed
Send and receive data:
read recv
ssize_t recv(int sockfd, void *buf, size_t len, int flags); //flags==MSG_PEEK reading data will not delete the data in the buffer
write send
ssize_t send(int sockfd, const void *buf, size_t len, int flags); //flags=1 emergency data
udp communication process
Server: Create report socket binding read-write closed
Client: Create a newspaper socket for reading and writing. Close
Send data:
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
dest_addr: the address information of the destination
addrlen: structure size
收数据: ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
src_addr: the other party’s address information
addrlen: the address of the structure size