How to send a text file from C to java and receive the same text file from java to C
-
I would like to know how to send a text file from C to java, in which java has to receive the file and send it back to C. I have developed the code, but i am facing error in the receive function #include #include #include #include #include #include #include #include #include #include #include #include #include #include int send_text(int socket) { FILE *text; char a[50]; int size, read_size, stat, packet_index; char send_buffer[8008], read_buffer[8008]; int wrt=0,sock_fd,tsize=0; packet_index = 1; int i=0; text = fopen("/home/sosdt009/Desktop/character3.txt", "r"); if (text == NULL) { printf("Error Opening text File:"); exit(-1); } printf("Getting text Size:\n"); gets(a); fseek(text, 0, SEEK_END); size = ftell(text); fseek(text, 0, SEEK_SET); printf("Total text size: %d \n", size); gets(a); //Send text Size printf("Sending text Size:\n",size); gets(a); send(socket, (void *)&size, sizeof(size), 0); /*do { stat = recv(socket, read_buffer, 1024, 0); }*/while(stat < 0) printf("Socket data:%s \n", read_buffer); gets(a); while(size>tsize) { //Read from the file into our send buffer read_size = fread(send_buffer,1,sizeof(send_buffer),text); printf("The size of send buffer:%c \n",send_buffer); gets(a); printf("The read size value is :%d \n", read_size); gets(a); //Send data through our socket do { stat = send(socket, send_buffer, read_size, 0); printf("The send size value is: %d \n", size); gets(a); printf("The read size value is: %d \n", read_size); gets(a); } while (stat < 0); printf("Packet %d, sent %d bytes.\n", packet_index, read_size); gets(a); //packet_index++; //Zero out our send buffer tsize = tsize+read_size; printf("The tsize value is:%d \n",tsize); gets(a); memset(send_buffer,0, sizeof(send_buffer)); if(read_size<=NULL) { printf("The connection is transferred to received text: \n"); gets(a); } } fclose(text); //close(socket); printf("Text successfully send:\n"); gets(a); return 0; } int receive_text(int socket) { int buffersize = 77,recv_size=0,read_size = 1, write_size,size; char *pBuf,a[50],b[77]; int errnom,i; FILE *textnew; size_t rec; textnew = fopen("/home/sosdt009/Desk
-
I would like to know how to send a text file from C to java, in which java has to receive the file and send it back to C. I have developed the code, but i am facing error in the receive function #include #include #include #include #include #include #include #include #include #include #include #include #include #include int send_text(int socket) { FILE *text; char a[50]; int size, read_size, stat, packet_index; char send_buffer[8008], read_buffer[8008]; int wrt=0,sock_fd,tsize=0; packet_index = 1; int i=0; text = fopen("/home/sosdt009/Desktop/character3.txt", "r"); if (text == NULL) { printf("Error Opening text File:"); exit(-1); } printf("Getting text Size:\n"); gets(a); fseek(text, 0, SEEK_END); size = ftell(text); fseek(text, 0, SEEK_SET); printf("Total text size: %d \n", size); gets(a); //Send text Size printf("Sending text Size:\n",size); gets(a); send(socket, (void *)&size, sizeof(size), 0); /*do { stat = recv(socket, read_buffer, 1024, 0); }*/while(stat < 0) printf("Socket data:%s \n", read_buffer); gets(a); while(size>tsize) { //Read from the file into our send buffer read_size = fread(send_buffer,1,sizeof(send_buffer),text); printf("The size of send buffer:%c \n",send_buffer); gets(a); printf("The read size value is :%d \n", read_size); gets(a); //Send data through our socket do { stat = send(socket, send_buffer, read_size, 0); printf("The send size value is: %d \n", size); gets(a); printf("The read size value is: %d \n", read_size); gets(a); } while (stat < 0); printf("Packet %d, sent %d bytes.\n", packet_index, read_size); gets(a); //packet_index++; //Zero out our send buffer tsize = tsize+read_size; printf("The tsize value is:%d \n",tsize); gets(a); memset(send_buffer,0, sizeof(send_buffer)); if(read_size<=NULL) { printf("The connection is transferred to received text: \n"); gets(a); } } fclose(text); //close(socket); printf("Text successfully send:\n"); gets(a); return 0; } int receive_text(int socket) { int buffersize = 77,recv_size=0,read_size = 1, write_size,size; char *pBuf,a[50],b[77]; int errnom,i; FILE *textnew; size_t rec; textnew = fopen("/home/sosdt009/Desk
-
I would like to know how to send a text file from C to java, in which java has to receive the file and send it back to C. I have developed the code, but i am facing error in the receive function #include #include #include #include #include #include #include #include #include #include #include #include #include #include int send_text(int socket) { FILE *text; char a[50]; int size, read_size, stat, packet_index; char send_buffer[8008], read_buffer[8008]; int wrt=0,sock_fd,tsize=0; packet_index = 1; int i=0; text = fopen("/home/sosdt009/Desktop/character3.txt", "r"); if (text == NULL) { printf("Error Opening text File:"); exit(-1); } printf("Getting text Size:\n"); gets(a); fseek(text, 0, SEEK_END); size = ftell(text); fseek(text, 0, SEEK_SET); printf("Total text size: %d \n", size); gets(a); //Send text Size printf("Sending text Size:\n",size); gets(a); send(socket, (void *)&size, sizeof(size), 0); /*do { stat = recv(socket, read_buffer, 1024, 0); }*/while(stat < 0) printf("Socket data:%s \n", read_buffer); gets(a); while(size>tsize) { //Read from the file into our send buffer read_size = fread(send_buffer,1,sizeof(send_buffer),text); printf("The size of send buffer:%c \n",send_buffer); gets(a); printf("The read size value is :%d \n", read_size); gets(a); //Send data through our socket do { stat = send(socket, send_buffer, read_size, 0); printf("The send size value is: %d \n", size); gets(a); printf("The read size value is: %d \n", read_size); gets(a); } while (stat < 0); printf("Packet %d, sent %d bytes.\n", packet_index, read_size); gets(a); //packet_index++; //Zero out our send buffer tsize = tsize+read_size; printf("The tsize value is:%d \n",tsize); gets(a); memset(send_buffer,0, sizeof(send_buffer)); if(read_size<=NULL) { printf("The connection is transferred to received text: \n"); gets(a); } } fclose(text); //close(socket); printf("Text successfully send:\n"); gets(a); return 0; } int receive_text(int socket) { int buffersize = 77,recv_size=0,read_size = 1, write_size,size; char *pBuf,a[50],b[77]; int errnom,i; FILE *textnew; size_t rec; textnew = fopen("/home/sosdt009/Desk
venkat28vk wrote:
...but i am facing error in the receive function
And you are withholding that error for what reason? You seriously need to remove all but the relevant pieces of code. Otherwise, few, if any, people will bother to wade through it all.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I would like to know how to send a text file from C to java, in which java has to receive the file and send it back to C. I have developed the code, but i am facing error in the receive function #include #include #include #include #include #include #include #include #include #include #include #include #include #include int send_text(int socket) { FILE *text; char a[50]; int size, read_size, stat, packet_index; char send_buffer[8008], read_buffer[8008]; int wrt=0,sock_fd,tsize=0; packet_index = 1; int i=0; text = fopen("/home/sosdt009/Desktop/character3.txt", "r"); if (text == NULL) { printf("Error Opening text File:"); exit(-1); } printf("Getting text Size:\n"); gets(a); fseek(text, 0, SEEK_END); size = ftell(text); fseek(text, 0, SEEK_SET); printf("Total text size: %d \n", size); gets(a); //Send text Size printf("Sending text Size:\n",size); gets(a); send(socket, (void *)&size, sizeof(size), 0); /*do { stat = recv(socket, read_buffer, 1024, 0); }*/while(stat < 0) printf("Socket data:%s \n", read_buffer); gets(a); while(size>tsize) { //Read from the file into our send buffer read_size = fread(send_buffer,1,sizeof(send_buffer),text); printf("The size of send buffer:%c \n",send_buffer); gets(a); printf("The read size value is :%d \n", read_size); gets(a); //Send data through our socket do { stat = send(socket, send_buffer, read_size, 0); printf("The send size value is: %d \n", size); gets(a); printf("The read size value is: %d \n", read_size); gets(a); } while (stat < 0); printf("Packet %d, sent %d bytes.\n", packet_index, read_size); gets(a); //packet_index++; //Zero out our send buffer tsize = tsize+read_size; printf("The tsize value is:%d \n",tsize); gets(a); memset(send_buffer,0, sizeof(send_buffer)); if(read_size<=NULL) { printf("The connection is transferred to received text: \n"); gets(a); } } fclose(text); //close(socket); printf("Text successfully send:\n"); gets(a); return 0; } int receive_text(int socket) { int buffersize = 77,recv_size=0,read_size = 1, write_size,size; char *pBuf,a[50],b[77]; int errnom,i; FILE *textnew; size_t rec; textnew = fopen("/home/sosdt009/Desk
-
Agree with Mr David, what type of error are you facing? is at compile time or runtime.. are you able to send file to JAVA Client? or it problem sending from java client to c++?