int receive_text(int socket) { int buffersize,recv_size = 0,read_size = 1, write_size, size; char *pBuf,a[50]; int errno; FILE *text; text = fopen("/home/sosdt009/Desktop/receivednew.txt", "w"); if (text == NULL) { printf("Error has occurred, text file could not be opened \n"); return -1; } //Loop while we have not received the entire file yet while (read_size > 0) { ioctl(socket, FIONREAD, &buffersize); printf("The Buffersize is :%d\n",buffersize); gets(a); printf("The size of socket is:%d\n",socket); gets(a); //We check to see if there is data to be read from the socket if (buffersize > 0) { printf("Buffersize value is :%d\n", buffersize); gets(a); pBuf = malloc(buffersize); if (!pBuf) { printf(errno, "Memory Error Cannot Allocate!\n"); gets(a); exit(-1); } read_size = recv(socket, pBuf, buffersize, 0); printf("Read size value is :%d \n",read_size); gets(a); printf("Buffersize value is:%d \n",pBuf); gets(a); if (read_size > 0) { printf("%d\n",strerror(errno)); printf("Data not written to the file:\n"); gets(a); goto free; } //Write the currently read data into our text file write_size = fwrite(read_size,1,sizeof(read_size),text); free(pBuf); printf("Write size value is :%d \n",write_size); gets(a); printf("Buffer size value is :%d \n",buffersize); gets(a); //Increment the total number of bytes read recv_size += read_size; printf("Received size value is:%d \n",recv_size); gets(a); printf("Read size value is :%d \n",read_size); gets(a); } } free: fclose(text); close(socket); printf("Text Successfully Received:\n"); gets(a); return 0; }
if (read_size > 0) { printf("%d\n",strerror(errno)); printf("Data not written to the file:\n"); gets(a); goto free; }
if
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)