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
Posts
-
How to send a text file from C to java and receive the same text file from java to C -
How to send a text file from C to java and receive the same text file from java to CI 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<time.h>
#include<errno.h>
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<sys/time.h>
#include<sys/ioctl.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<sys/select.h>
#include<sys/socket.h>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 * -
Live chat with an UserHi, I would like to propose an suggestion. For example consider i am posting a question and few users are responding to it and there is a particular user who is more involved in resolving the question. Just give an option or add an icon so that i can chat with the user instantly like Skype or g talk. This shall provide more user friendly environment to the users.
-
How to send and receive images in C programmingHi, I would like to know how to send and receive messages in c code and is it possible to achieve this in tcp/ip model.
-
How to send an acknowledgement message to the server stating that client has received some dataHi, I am able to run tcp/ip program and i am able to send and receive data but once i receive data i should send an acknowledgement stmt how to achieve this....