- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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't find good methods..) Thanks again http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
<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'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't find good methods..[/b] --- Quote End --- you can reuse your buffers...- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
maybe you can also post the code for sending?
the receiving code looks good for me.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page