Sunday, 15 May 2011

java - Client reading too many bytes from server? -


I am writing a simple FTP client / server setup; the client should be able to get the file from the server and the result is bytes Place in the form of / retr_files / filex. Proper responses are sent to the server, and file 1 is actually created in the folder. However, many bytes were sent (or were received) I tested it on 9.6 KB file and the file was client-side 16.6kB. strange. I think I am clarifying something here, can someone help me? Thanks!

Relevant code:

Customer:

  BufferedReader inFromServer_d = null; If (welcomeSocket! = Null) {if (WelcomeSocket.isClosed ()) {welcomeSocket.close (); }} Try {WelcomeSocket = new ServerSocket (Port); System.out.print ("PORT" + myIP + "," + num1 + "," + num2 + "\ r \ n"); Out.Litebites ("port" + mip + "," + number 1 + "," + num2 + "\ r \ n"); System.out.print (parseReply (GetResponse ())); System.out.print ("RETR" + pathname + "\ r \ n"); Out.Litebites ("RETR" + PATNAM + "\ r \ n"); String Answer = Pars Repli (getResponse ()); If (Answer: Chart (10) == '1') {System.out.print (Answer); System.out.print (parseReply (GetResponse ())); Try {ClientSocket_d = welcomeSocket.accept (); } Hold (IOException e) {System.out.print ("GET failed, FTP-data port not allocated. \ R \ n"); System.exit (-1); } InFromServer_d = New BufferedReader (New InputStreamReader (clientSocket_d.getInputStream ())); // READ Bufford Reader bufffered reader = infraversver_d; Fiver output = new flamer ("retr_file / file" + retort cnt); Buffer water buffer = new buffed vaitters (output); string length; While ((= width = buffed reader.readline ())! = Null {bufferedWriter.write (length + "\ n");} BufferedReader.close (); bufferedWriter.close (); clientSocket_d.close ();   

Server:

  // TCP connect data output outputout client_d = zero; socket client socket 1 = tap; try {ipAddress = ipAddress.substring (0, ipAddress.length () - 1); ClientSocket1 = new socket (IP address, port number); OutToClient_d = new dataOPTOP (clientSocket1.getOutputStream ());} hold (unknownHostException E) {out.writeBytes ("425 can not open data connection. \" \ N ");} Buf FeredReader bufferedReader = new BufferedReader (string); string length; while ((= length = buffed reader.readline ())! = Null {outToClient_d.writeBytes (length + "\ n");} Out.writeBytes ("250 requested file actions Complete. \ R \ n "); bufferedReader.close (); clientSocket1.close (); outToClient_d.close ();   

}

Do not use readers and authors and readLine (). All files are not text files, and all text files do not contain line breaks.

No comments:

Post a Comment