Results 1 to 4 of 4
- 10-09-2010, 05:21 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 11
- Rep Power
- 0
File transfer hanging - Jar files in linux only!
Hey,
Not sure whether to post this in the advanced or beginner, I've been Java coding for years but been a while since I did Client-Server and this seems like it could be a simplish issue, although it's driving me insane!
Basically I have a client server file transfer program.
Everything works fine in Windows, files transfer as they should.
When I go to use linux, it seems to work with most files, but when I go to transfer the files it's made for (Jar files for a plugin framework) it hangs, the client writes the file and the server doesn't finish reading and then the client keeps waiting for a server response.
Code below
Java Code:Client.java Socket sock = new Socket("localhost",13267); System.out.println("Connecting..."); int fileLength = (int) file.length(); BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream())); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); System.out.println("Sending Filename: "+file.getName()); out.write(file.getName()); out.newLine(); out.flush(); System.out.println("Sending Filelength: "+fileLength); // have to convert to a string or the bufferedwriter will try write // fileLength as a character out.write(Integer.toString(fileLength)); out.newLine(); out.flush(); byte [] byteArray = new byte [fileLength]; FileInputStream fileInput = new FileInputStream(file); BufferedInputStream bufferedFileInput = new BufferedInputStream(fileInput); bufferedFileInput.read(byteArray,0,byteArray.length); OutputStream output = sock.getOutputStream(); System.out.println("Sending File..."); output.write(byteArray,0,byteArray.length); output.flush(); System.out.println("Sending..."); System.out.println("Server: "+in.readLine());Code looks fine but it hands in linux when trying to transfer my Jars...Java Code:Server.java ServerSocket servsock = new ServerSocket(13267); while (true) { System.out.println("Waiting..."); Socket sock = servsock.accept(); System.out.println("Accepted connection : " + sock); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); InputStream input = sock.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(input)); String fileName = in.readLine(); System.out.println("Received fileName :"+fileName); String fileSize = in.readLine(); System.out.println("Received fileSize :"+fileSize); File outputFile = new File("temp/"+fileName); FileOutputStream output = new FileOutputStream(outputFile); byte[] byteArray = new byte[Integer.parseInt(fileSize)]; System.out.println("Receiving File..."); input.read(byteArray); System.out.println("Received File..."); output.write(byteArray, 0, byteArray.length); out.write("done"); out.newLine(); out.flush(); sock.close(); }
And I know sending the file in one chunk isn't great but I couldn't get it to work in pieces, it was hanging in both windows and linux then.
- 10-10-2010, 02:33 AM #2
it might be the out.newline(). on Unix platforms this would write a "\n" character, while on Windows this would write a "\r\n"
And that I wonder if the the other side of the transfer (client or server) was on different (windows / linux) than the sender, if that difference in end line would cause different than expected number of bytes, which if it is less might cause it to hang waiting for more.
- 10-11-2010, 09:15 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 11
- Rep Power
- 0
They're both running on linux on the same machine, it's a Virtual machine btw incase that makes a difference.
But the newLine() shouldn't make a difference, I don't use that for writing the file (I can't, OutputStream doesn't have that method). I only use that for writing responses like words/sentences and they read and write fine.
It's the file part that hangs, and only for Jar files :confused:
It works fine for pdfs, java files etc.
It's driving me mad!!! Makes no sense :confused: :(
- 10-11-2010, 10:13 AM #4
Member
- Join Date
- Sep 2010
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
JFrame Hanging When Called From Another Class
By al_Marshy_1981 in forum AWT / SwingReplies: 5Last Post: 03-30-2010, 07:04 PM -
can you tell how transfer a List eg. created as...between files jsp/java
By lse123 in forum JavaServer Pages (JSP) and JSTLReplies: 21Last Post: 02-10-2010, 08:52 AM -
SWT program on Linux can find jar files.
By glmarsh in forum SWT / JFaceReplies: 1Last Post: 07-20-2009, 07:02 PM -
loading flash files in linux
By rajeshang in forum AWT / SwingReplies: 0Last Post: 05-31-2008, 01:59 PM -
Files not completely deleted on Linux
By amamare in forum Advanced JavaReplies: 0Last Post: 12-19-2007, 02:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks