Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

tcp socket program puzzle

Altera_Forum
Honored Contributor II
1,349 Views

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 can define in the program. I have used different methods to resolve this problem, but the result is not good.  

Can any one give me some suggestions? Thanks a lot!
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
517 Views

if i understand you right, you cannot define a buffer, which is big enough; for example: 

 

char buffer; 

 

so if i'm right you should try to use the malloc function ; in this case (*EDIT* for buffers greater than 1MB) you need to enable a kernel option to do so (for big portions of memory): 

Processor type and features --> Allow allocating large blocks.... 

Greets 

 

helmchen
0 Kudos
Altera_Forum
Honored Contributor II
517 Views

 

--- Quote Start ---  

originally posted by helmchen@Jan 23 2007, 05:10 PM 

if i understand you right, you cannot define a buffer, which is big enough; for example: 

 

char buffer; 

 

so if i'm right you should try to use the malloc function ; in this case (*edit* for buffers greater  than 1mb) you need  to enable a kernel option to do so (for big portions of memory): 

processor type and features --> allow allocating large blocks.... 

greets 

 

helmchen 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=20794)</div> 

--- Quote End ---  

 

 

Thank you helmchen, you have understand me right. 

Can I ask two more questions? 

1, I have seen the option in the configure interface, but I wonder the kernel take use of what for the large blocks? 

2, Can I just use the limited buffer to carry out large data transmission? For example, send several times?(I have tested, but still can&#39;t find good methods..) 

Thanks again http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
0 Kudos
Altera_Forum
Honored Contributor II
517 Views

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

1, I have seen the option in the configure interface, but I wonder the kernel take use of what for the large blocks?[/b] 

--- Quote End ---  

 

well i&#39;m not a kernel crack. Maybe you take a look at 

http://www.linuxdevices.com/articles/at7777470166.html (http://www.linuxdevices.com/articles/at7777470166.html) and in the kernel docs. 

 

Maybe someone else can explain it in short. 

 

<div class='quotetop'>QUOTE </div> 

--- 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&#39;t find good methods..[/b] 

--- Quote End ---  

 

 

you can reuse your buffers...
0 Kudos
Altera_Forum
Honored Contributor II
517 Views

 

--- 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&#39;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&#39;s not a good way, so I am searching the good ways to reuse buffer. Do you have any good suggestions?
0 Kudos
Altera_Forum
Honored Contributor II
517 Views

maybe you can also post the code for sending? 

the receiving code looks good for me.
0 Kudos
Reply