Results 1 to 5 of 5
Thread: frozen program
- 10-10-2009, 11:36 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 70
- Rep Power
- 0
frozen program
Hello,
I am writing a program, and part of it is to transfer a file. However, when i debug, it seems to be getting stuck when the client reads the filesize sent by the server, heres the code:
Server
Java Code:ServerSocket servsock = new ServerSocket(13267); Socket sock = servsock.accept(); byte [] mybytearray = new byte [(int)myFile.length()]; FileInputStream fis = new FileInputStream(myFile); BufferedInputStream bis = new BufferedInputStream(fis); bis.read(mybytearray,0,mybytearray.length); OutputStream os = sock.getOutputStream(); os.write((int)myFile.length()); System.out.println(myFile.length()+""); os.write(mybytearray,0,mybytearray.length); os.flush(); sock.close();
Client
Java Code:try{ int bytesRead; int current = 0; Socket sock = new Socket(ip_fld.getText(),13267); FileOutputStream fos = new FileOutputStream("file.lxs"); BufferedOutputStream bos = new BufferedOutputStream(fos); InputStream is = sock.getInputStream(); int filesize = is.read(); //here is where it gets stuck System.out.println(filesize); byte [] mybytearray = new byte [filesize]; bytesRead = is.read(mybytearray,0,mybytearray.length); current = bytesRead; do { bytesRead = is.read(mybytearray, current, (mybytearray.length-current)); if(bytesRead >= 0) current += bytesRead; } while(bytesRead > -1); bos.write(mybytearray, 0 , current); bos.flush(); long end = System.currentTimeMillis(); System.out.println(end-start); bos.close(); sock.close(); Runtime.getRuntime().exec("cmd /c start luxconsole.exe file.lxs"); } catch(Exception e){ }
- 10-10-2009, 11:43 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You are swallowing exceptions.
Do an
in your catch blocks to find out what is happening.Java Code:e.printStackTrace();
- 10-10-2009, 11:50 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 70
- Rep Power
- 0
No exception is showing.
Can you even send and recieve ints? It says bytes, but the argument is int. If not, how do you send ints?
- 10-10-2009, 11:57 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Do read the API specs for the methods you are using. read does not return the file size.
Also the method blocks if there is no input data is available.
- 10-11-2009, 05:25 AM #5
Member
- Join Date
- Mar 2009
- Posts
- 70
- Rep Power
- 0
Similar Threads
-
Execute A program from a Program!
By Moncleared in forum Advanced JavaReplies: 2Last Post: 02-22-2009, 04:17 PM -
Executing a program within a program
By gibsonrocker800 in forum New To JavaReplies: 5Last Post: 05-12-2008, 08:24 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks