Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  downloading files with java problem  (Read 1823 times)
0 Members and 1 Guest are viewing this topic.
Offline kappa
« League of Dukes »

JGO Kernel

Medals: 120
Projects: 15


« Posted 2007-10-05 17:23:53 »

I have an app that downloads a java file using the code below, problem is that it works fine for me and many others but some users get a "Connection timed out: connect" error, not really sure what could be causing this.

One guess is that it might be caused by the the buffer size which is set to 64kb. I have tried a smaller buffer size, like 4kb but found it took a lot longer to download, using the bigger buffer size was much faster, could it be that i need to use a smaller buffer and sacrifice speed?

Not really sure what is the correct way to do this, any help or solution on the best way to do this would be appreciated.


public void downloadFile(URL url) throws Exception {
      // reset percentage
      percentage = 0;

      // create buffer
      byte buffer[] = new byte[65536];
      // open connection
      URLConnection urlconnection = url.openConnection();
      // get file size
      totalFileSize = urlconnection.getContentLength();

      // get location to save file
      String filename = getFileLocation(url);
      InputStream inputstream = urlconnection.getInputStream();
      FileOutputStream fos = new FileOutputStream(filename);
      int bufferSize;
      while ((bufferSize =, 0, buffer.length)) != -1) {
         fos.write(buffer, 0, bufferSize);
         currentFileSize += bufferSize;
         percentage = (currentFileSize * 100) / totalFileSize;
Offline Mr_Light

Senior Devvie

Medals: 1


« Reply #1 - Posted 2007-10-05 23:54:43 »

I haven't looked at the actaul inner workings of the implementation.

but, connection timed out, means in general that it didn't recieve an ack for a specified timeout. this also applies to never have recieved an ack in the first place, in other words there was never a connection.

now you can set a longer time out( ) but under normal circumstances the default should work.

My gues would be that there route to the host is messed (like it beeing absent(no route to host), check if the ppl involved are connected to the internet etc)

Buffer only has a really(really-really) slim chance of effecting the process (mostly though faulty implementations.) I though you got some other exception altogether if the buffer was backed up. but again I must note that I have looked at the implementation specifically.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Cero
« Reply #2 - Posted 2009-04-07 22:26:37 »

do you still use this code ? any developments since then regarding this problem ?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kappa
« League of Dukes »

JGO Kernel

Medals: 120
Projects: 15


« Reply #3 - Posted 2009-04-08 08:44:46 »

wow pretty old post revived, I did eventually find a solution to this, what I did was wait for a specific amount of time, if a connection was not received in that time, then kill the connection and try again.

I believe this was an old bug in the jre that was supposed to be fixed, however it still somehow happens with the Opera Java Plugin.

You can find my final solution to this here in method downloadJars(String path).
Offline Cero
« Reply #4 - Posted 2009-04-08 16:38:54 »

ah ok, thx =D

Pages: [1]
  ignore  |  Print  

EgonOlsen (59 views)
2018-06-10 19:43:48

EgonOlsen (42 views)
2018-06-10 19:43:44

EgonOlsen (61 views)
2018-06-10 19:43:20

DesertCoockie (241 views)
2018-05-13 18:23:11

nelsongames (142 views)
2018-04-24 18:15:36

nelsongames (141 views)
2018-04-24 18:14:32

ivj94 (883 views)
2018-03-24 14:47:39

ivj94 (144 views)
2018-03-24 14:46:31

ivj94 (795 views)
2018-03-24 14:43:53

Solater (159 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!