--- Quote Start ---
Can I just use the limited buffer to carry out large data transmission? For example, send several times?(I have tested, but still can't find good methods..
--- Quote End ---
you can reuse your buffers...
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=20816)</div>
--- Quote End ---
Thanks again, kind helmchen.
I have tried to reuse the buffers, for example, server send two times and client receive two times. But the result is not right..
I only found a method that is(TCP):
After send and receive once, client close the connection. And then establish another connetion and perform another transmition..
So in this way, If I need reuse my buffer ten times to finish the transmition, I have to establish and close the connection ten times..
Below is a segment of the client program to help you understand me.
----------------------------------------------------------------------
//The first connection, receive 1500 bytes
sockfd = socket(AF_INET,SOCK_STREAM,0);
bzero((struct sockaddr*)&serveraddr,sizeof(serveraddr));
serveraddr.sin_family=AF_INET;
serveraddr.sin_port=htons(5000);
inet_pton(AF_INET,argv[1],&(serveraddr.sin_addr));
if((connect(sockfd,((struct sockaddr*)&serveraddr),sizeof(serveraddr)))<0)
printf("connect error!!\n");
recvbyte=recv(sockfd,recvbuff,1500,0);
printf("recvbyte1=%d\n",recvbyte);
close(sockfd);
//The second connection,receive 1500 bytes.
sockfd = socket(AF_INET,SOCK_STREAM,0);
bzero((struct sockaddr*)&serveraddr,sizeof(serveraddr));
serveraddr.sin_family=AF_INET;
serveraddr.sin_port=htons(5000);
inet_pton(AF_INET,argv[1],&(serveraddr.sin_addr));
if((connect(sockfd,((struct sockaddr*)&serveraddr),sizeof(serveraddr)))<0)
printf("connect error!!\n");
recvbyte=recv(sockfd,recvbuff,1500,0);
printf("recvbyte2=%d\n",recvbyte);
close(sockfd);
...
---------------------------------------------------------------------
I think it's not a good way, so I am searching the good ways to reuse buffer. Do you have any good suggestions?