I'm implementing Client/Server File send and receive.
Implementation:Client in C and Server in Java.
Part of the C code being sent:
long count;
FILE *file;
char *file_data;
file=fopen("test.txt","rb");
fseek (file , 0 , SEEK_END);
count = ftell (file);
rewind (file);
file_data=(char*)malloc(sizeof(char)*count);
fread(file_data,1,count+1,file);
fclose(file);
if ((numbytes = send(sockfd, file_data, strlen(file_data)+1 , 0)) == -1)
{
perror("client: send");
exit(1);
}
Part of Java code receiving:
public String receiveFile()
{
String fileName="";
try
{
int bytesRead;
InputStream in = clientSocket.getInputStream();
DataInputStream clientData = new DataInputStream(in);
fileName=clientData.readUTF();
}
}
After readUTF() function is used, the server hangs up or is in infinite loop and doesnt proceed further. I've tried BufferedReader with readLine(). There is an error that "no suitable constructor found for BufferedReader(InputStream) & readLine() gives a warning. Any other alternative besides BufferedReader??