Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. 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 C

Scheduled Pinned Locked Moved C / C++ / MFC
javahelptutorial
7 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venkat28vk
    wrote on last edited by
    #1

    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

    L D T 3 Replies Last reply
    0
    • V venkat28vk

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You already posted this question at How to send a file from C to java and receive the same file to C from java[^]. Please stick to one forum.

      1 Reply Last reply
      0
      • V venkat28vk

        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

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • V venkat28vk

          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

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          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++?

          CPalliniC 1 Reply Last reply
          0
          • T ThatsAlok

            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++?

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            Wow, Alok! It has been a while... :)

            In testa che avete, signor di Ceprano?

            T 2 Replies Last reply
            0
            • CPalliniC CPallini

              Wow, Alok! It has been a while... :)

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Really ! ;P

              1 Reply Last reply
              0
              • CPalliniC CPallini

                Wow, Alok! It has been a while... :)

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                Jokes apart :-) , have started working in VC++ again after long time...happy to back in fold

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups