LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2004, 01:07 PM   #1
abdobl
LQ Newbie
 
Registered: Sep 2004
Location: Tripoli
Posts: 22

Rep: Reputation: 15
Thumbs up I need same help


Hi All
I working in my project and I have same problem it to complicated to explain , but I will explain it in small Example :-
I use 2 computer run linux Red Hat 9 connected by using cross over link (client/server)
I need tow transfer huge data by using socket interface(with c) and this is my programs


/* server.c */

#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<stddef.h>
#include<math.h>
//#define RAW 50
//#define COL 50
main(int argc,char *argv[])
{
int cont,create_socket,new_socket,addrlen;
//int bufsize ;
int *buffer ;
buffer= calloc(380000000,1);
struct sockaddr_in address;
time_t s,f;
double t1,t2,temp;
struct timeval tp;
//int bufsize ;
//int *buffer = malloc(120000);

int x=0,asd;
printf("\x1B[2J");
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The socket was created\n");
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(15500);
if (bind(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
printf("Binding Socket\n");
listen(create_socket,6);
addrlen = sizeof(struct sockaddr_in);
new_socket = accept(create_socket,(struct sockaddr *)&address,&addrlen);
if (new_socket > 0){
printf("The Client %s is connected...\n",inet_ntoa(address.sin_addr));
for(cont=1;cont<5000;cont++)
printf("\x7");
}
// if()

int i,g=0,j,u,t=0,y,d=0,q,k;

/* for(i=0;i<bufsize;i++)
buffer[i]=0;
*/
// for(i=0;i<(RAW/5);i++)
for(j=0;j<50000;j++)
{
buffer[j]=t;
t++;
}
//printf("the result is as follows : \n\n");
send(new_socket,buffer,380000000,0);

/*for(i=(RAW/2);i<RAW;i++)
for(j=0;j<COL;j++)
{ //printf("the result is as follows : \n\n");
while(d<(RAW/2))
{ //printf("the result is as follows 10: \n\n");
for(y=0;y<COL;y++)
{
buffer[t]=a[d][y];
//printf("buffer[%d]=%d\t",t,buffer[t]);
t++;
}

d++;
}
if(d==(RAW/2))
{
for(q=0;q<RAW;q++)
for(y=0;y<COL;y++)
{
buffer[t]=b[q][y];
printf("buffer[%d]=%d\t",t,buffer[t]);

t++;
}
asd=gettimeofday(&tp, NULL);
t1=(double)tp.tv_sec+(1.e-6)*tp.tv_usec;
time(&s);
// printf("the result is as follows : \n\n");
send(new_socket,buffer,bufsize,0);
d++;
}

for(k=0;k<RAW;k++)
c[i][j]+=a[i][k]*b[k][j];

}

t=0;
recv(new_socket,buffer,bufsize,0);
for(i=0;i<(RAW/2);i++)
for( j=0;j<COL;j++)
{
c[i][j]=buffer[t];
t++;
}
for(i=0;i<RAW;i++)
for(j=0;j<COL;j++)
//printf("c[%d][%d]=%d\t",i,j,c[i][j]);


time(&f);
asd=gettimeofday(&tp, NULL);
t2=(double)tp.tv_sec+(1.e-6)*tp.tv_usec;
temp=t2-t1;

/*printf("\n\n%s\n", ctime(&s));
printf("%s\n", ctime(&f));
printf("%f in sec , %f in sec:usec\n", difftime(f, s),temp);
*/
free(buffer);
close(new_socket);
close(create_socket);

/* client.c */

#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
//#define RAW 50
//#define COL 50
main(int argc,char *argv[])
{
int create_socket;
//int bufsize;
int *buffer;
buffer= calloc(380000000,1);
struct sockaddr_in address;
// BUF_MEM_grow(int *buffer,int 2000 );
printf("\x1B[2J");
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The Socket was created\n");
address.sin_family = AF_INET;
address.sin_port = htons(15500);
inet_pton(AF_INET,argv[1],&address.sin_addr);

if (connect(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
printf("The connection was accepted with the server %s...\n",inet_ntoa(address.sin_addr));
int x=0,d,i;
//a[RAW][COL],b[RAW][COL],c[RAW][COL],i=0,j,t=0,k,q,w;
/* for(i=0;i<RAW;i++)
for(j=0;j<COL;j++)
{
a[i][j]=0;
b[i][j]=-1;
c[i][j]=0;
} */
// for(i=0;i<100;i++)
//buffer[i]=9;



//printf("the result is as follows 1: \n\n");
recv(create_socket,buffer,380000000,0);
/* for(i=0;i<50000;i++)
printf("the buffer[%d]=%d\n",i,buffer[i]);
printf("the buffer[44290]=%d the buffer[43999]=%d\n",buffer[44290],buffer[443999]);*/
for(i=100;i<50000;i++)
if(buffer[i]==0)
printf("the buffer error[%d]=%d,buffer[36890]=%d\n\n",i,buffer[i],buffer[36890]);
printf("the buffer{36895}=%d,the buffer{36899}=%d,the buffer{36900}=%d",buffer[36895],buffer[36899],buffer[36900]);

/* for(i=0;i<bufsize;i++)
//for(j=0;j<COL;j++)
printf("buffer[%d]=%d\n",i,buffer[i]);
*/
//for(i=0;i<(RAW/2);i++)
/* for(i=0;i<(RAW/2);i++)
for(j=0;j<COL;j++)
{
printf("buffer[%d]=%d\t",t,buffer[t]);
a[i][j]=buffer[t];
t++;
} */

/* for(i=0;i<RAW;i++)
for(j=0;j<COL;j++)
{
b[i][j]=buffer[t];
printf("b[%d][%d]=%d\t",i,j,b[i][j]);

t++;
}*/

/* t=0;
for(i=0;i<(RAW/2);i++)
for(j=0;j<COL;j++)
{
for(k=0;k<RAW;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
// printf("c[%d][%d]=%d\n",i,j,c[i][j]);
buffer[t]=c[i][j];
t++;
} */
//send(create_socket,buffer,15000,0);
// printf("The message has been sent to the server.\n");

//}while (strcmp(buffer,"/q"));
free(buffer);
close(create_socket);
}











My problem in the data was receive at client (recv function) the out put of last part of them is zero value
If any one has had a similar experience with this please tell me in detail




Than you
 
Old 09-20-2004, 04:05 PM   #2
jwstric2
Member
 
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
First, thats a huge amount of data to be received from one call, 365 MBs. I don't even have enough resources to attempt the program. Second how much data is gotten from recv,, it returns the read bytes or less than 0 on error and set errno. Try and break the data up to see if in fact the data is correct beofre sent. Finally, thats a crappy title to a forum. I search for answers a lot and cant find what Im looking for even though its been posted because of crappy titles.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration