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
1 Posts 1 Posters 0 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<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 *

    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