I started with networking today..THis piece of code is giving me some problem, can some one help me??
client side:
Code:
//sockfd is the socket descriptor that I am using to send and recv data.
int c,i=1;
FILE *fp;
char *buf1;
cahr *buf11;
buf1=malloc(sizeof(char)*50);//the starting address of hte space allocated is in buf1
buf11=buf1; //store the starting address in buf11
fp=fopen("text.c","r");
while((c=getc(fp))!=EOF)
{
*buf1=c;
buf1++;
i++;
}
fclose(fp);
*buf1= '\0' ; // IS THIS REQD??
buf1=buf11;
//buf1 is now pointing to the starting point of the segment allocated.
//i+1 is the total number of bytes to be sent
size=send(sockfd,buf1,i+1,0);
printf("bytes sent : %d\n",size);
printf("bytes to be sent %d\n",i+1);
server side :
Code:
// new_fd is the socket descriptor returned by accept()
int size;
char *buf2;
buf2= malloc(sizeof(char)*50);
size=recv(new_fd,buf2,50,0);
printf("bytes recvd :%d\n",size);
prirntf("%s",buf2);
I am able to recv only 4 or 5 characters ,though the size parameter(in the CLIENT side) has the right value ..and I get a segemntation fault..can some one help me out