Socket data Reading and Writing of Reading Notes in linux High performance Network programming
Data read and write is divided into TCP data read and write, UDP data read and write, general data read and write
1.TCP data read and write
Definition: socket is the connection between user space and kernel space. TCP and UDP are the first layer of the kernel.
Explanation: read and write for files are also applicable to socket
Example: system call to TCP stream data
1.1ssize_t recv (int sockfd,void buf,size_t len,int flags)
1.2ssize_t send (int sockfd,const void buf,size_t len,int flags)
Parameter explanation:
1.3buf and len refer to the location and size of the cache
1.3.1flags is usually 0
Recv successfully returns the length of the data actually read
Note: the actual read length may be less than the expected len, so call recv multiple times
Recv may return 0, which means the other party has closed the connection.
Recv error returns-1 and sets errno
1.4send is basically the same as above.
The instance code sent
Int main (int argc, char * argv []) {if (argc)