Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Socket data Reading and Writing of Reading Notes in linux High performance Network programming

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report