The recv or read function () in tcp reads network data.
Source: Internet
Author: User
The recv or read function () in tcp reads network data-Linux general technology-Linux programming and kernel information. The following is a detailed description. : 0 wszxc
This afternoon, the data was transmitted over the recv or read network. However, after the transmission was completed, the programs on both the server and the host stopped, or they were reading data all the time, but nothing is read.
So my program is stuck there.
The procedure is as follows:
Server:
// Download file functions
Int download_file (char * buf, int c_sockfd)
{
Int fd; char buff [100]; int k;
Fd = open (buf + 3, O_RDWR );
While (k = read (fd, buff, 100)> 0)
{
Write (c_sockfd, buff, 100 );
Memset (buff, 0,100 );
Printf ("the sent data is % d bits. \ N ", k );
}
Printf ("Data Transmission completed ");
Close (fd );
Return 0;
}
Client Program:
/Download file functions
Int download_file (int c_sockfd)
{
Int fd;
Char buff [100];
Int k;
Fd = open ("/home/wangli/wujun/tt.txt", O_RDWR | O_CREAT );
While (k = read (c_sockfd, buff, 100)> 0) // test whether read is performed once or cyclically.
{
Write (fd, buff, 100 );
Memset (buff, 0,100 );
Printf ("the received data is % d bits. \ N ", k );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.