while(size!=0)
			{
			printf("loop start");
			printf("File Size in int: %d \n",size);
			byte_count = recv(sock,recv_data, 1024,0);
			recv_data[byte_count] = '\0';
			printf("hhahaha %d \n",10);
			
			printf("char is:%c \n",recv_data[0]);
			//fputc(recv_data[0], fpW);
			
			size=size-1;
			printf("loop end");			
			}
			fclose(fpW);




This is a piece of Client side code .. i am sending data from Server Side but when i receive it on client side the recv call is blocked

the code how m i sending data from server is:

FILE *fp;
				int ch;
				if((fp = fopen("file.txt","rb"))==NULL) {
					printf("Cannot open Source file.\n");
					exit(1);
				}
				struct stat fileInfo;
    				stat("file.txt", &fileInfo);
				int size=(int)fileInfo.st_size;				
				printf("File Size: %d \n",size);
				fflush(stdout);
				

				char msg1[10];
				sprintf(msg1,"%i",size);
				
				printf("File Size: %s \n",msg1);
				
				send(client, msg1, sizeof(msg1),0);
				//strcpy(msg1,NULL);
				//msg1[0]='\0';
				while((ch = (int)fgetc( fp )) != EOF) {
				//	sprintf(msg1,"%c",ch);			
					printf("%c",ch);
					send(client,&ch, 1,0);
				}

				fclose(fp);

Please tell me why does it block on recv call
its urgent ... :(

recv() blocks untill it gets something to read from the inputted socket.
If its blocked clearly means that there is no data to be read.
Check your connection both from server side and client. Check whether the server is connected to the particular client or not and also in the client check the connected server (check the port number, is it the same or not).

recv() blocks untill it gets something to read from the inputted socket.
If its blocked clearly means that there is no data to be read.
Check your connection both from server side and client. Check whether the server is connected to the particular client or not and also in the client check the connected server (check the port number, is it the same or not).

I've been checking all these things for last 5 hours but every thing is fine .... thats y I've posted the code above .... please see if I've left any error that i don't know about ....

I've been checking all these things for last 5 hours but every thing is fine .... thats y I've posted the code above .... please see if I've left any error that i don't know about ....

can u please send me the complete files (both client and server) at
dharmendra.kalita@ge.com

may be i can find out the problem out there

thanks

can u please send me the complete files (both client and server) at
dharmendra.kalita@ge.com

may be i can find out the problem out there

thanks

No I've just solved the Problem
In fact I was thinking that send() is also blocking call that waits for client to receive sent data .... but then I realized only recv() is blocking but send() is not blocking .... and this concept solved the problem.

@ above Thanks a lot dear .... u helped me a lot too

No I've just solved the Problem
In fact I was thinking that send() is also blocking call that waits for client to receive sent data .... but then I realized only recv() is blocking but send() is not blocking .... and this concept solved the problem.

@ above Thanks a lot dear .... u helped me a lot too

u r welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.