• Post Reply Bookmark Topic Watch Topic
  • New Topic

file transfer roblem  RSS feed

 
sudipta ghosh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing a problem when i am transfering a file from server to client.Its ok for any type of file txt or exe when i am using BufferedInput/OutputStrem.
But problem arise for exe file (ascii 128-160)when i am using BufferedReader/Writer .I am receiving the same file size.When i am opening the file in Hex editor in client side some bytes r different.
When i am sending ascii char 128-160 I am always receiving 63.I didnt find what is the problem.
another problem when i am opening 2 input/output stream on same socket in server and client socket
then i am facing proble see the following code.
FileInputStream fin=new FileInputStream("iotest.txt");
serversock=new ServerSocket(5555);
System.out.println("Listening.....");
clientsock=serversock.accept();
din1=new BufferedReader(new InputStreamReader(clientsock.getInputStream()));
dout1=new BufferedWriter(new OutputStreamWriter(clientsock.getOutputStream()));
din=new BufferedInputStream(clientsock.getInputStream());
dout=new BufferedOutputStream(clientsock.getOutputStream());
din2=new DataInputStream(clientsock.getInputStream());
dout2=new DataOutputStream(clientsock.getOutputStream());
size=fin.available();
dout1.write(new Integer(size).toString());
//dout.write(size);
dout1.newLine();
dout1.flush();
//dout2.writeByte(162);
//dout2.writeInt(size); problem in client not getting the int
//dout2.writeInt(size);
//dout2.flush();
System.out.println(new Integer(size).toString());
Thread.sleep(1000);
dout2.writeInt(size); but here its OK
dout1.flush();

in client
FileOutputStream fout=new FileOutputStream("iotest1.txt");
clientsock=new Socket("10.140.13.178",5555);
DataOutputStream doutt=new DataOutputStream(System.out);
System.out.println("connected.....");
din1=new BufferedReader(new InputStreamReader(clientsock.getInputStream()));
dout1=new BufferedWriter(new OutputStreamWriter(clientsock.getOutputStream()));
din=new BufferedInputStream(clientsock.getInputStream());
dout=new BufferedOutputStream(clientsock.getOutputStream());
din2=new DataInputStream(clientsock.getInputStream());
dout2=new DataOutputStream(clientsock.getOutputStream());
data=din1.readLine();
System.out.println(size);
//din2.read();
//din1.read();
test=din2.readInt();
size=new Integer(data).intValue();
System.out.println("\nsize is "+size+"\n");
test++;
System.out.println("\n test="+test);
//doutt.writeInt(test);
System.out.println("OK\n");
int ch;

 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your first call to System.out.println(size) happens BEFORE you do size=new Integer(data).intValue(); So, it will print whatever value it had before possibly 0 Move the size=new Integer(data).intValue(); to before you print it the first ime and let me know how things go.
------------------
Hope This Helps
Carl Trusiak, SCJP2
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!