Forum Discussion
Altera_Forum
Honored Contributor
19 years agotcp socket program puzzle
Hello everyone: I am learning and testing TCP socket program. In my application, I want to send and receive a great deal of data at one time. So the quantity of data exceed the size of array I...
Altera_Forum
Honored Contributor
19 years ago --- 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?