applet downloading media

So once youve got your game done and its online, inside the applet on its startup you can connect to an url and download game media.
(to load levels and graphics and possibly character info.)

I was just wondering is there a way to code this so it happens once only when the user first gets the applet, or do you have to always reload all the media
every time the applet is loaded.
Because it seems like your wasting a lot of server bandwidth (that you might have to pay for) and I was just wondering if you could save send sometimes.

Another way to do this would be to have a dedicated server that also manages the game send the media that the client applet requires. (in the case of maybe an MMO implementation)

Would there be some way to keep media (as long as it never changes ever once during the game, like say a static environment and static model pieces) so next time
you load the applet up it starts faster? (and doesnt resend everything it already sent last time)

Ive just got an idea, is it possible to have an “external download” where it places in some directory, e.g. “c:\gamename” that the applet then reads out of all the game data so it needent be downloaded every time the applet starts.

A signed applet can write stuff out to a cache. But otherwise yes you’re stuck with reloading every time (like Flash is).

Cas :slight_smile:

Yeh thanks.

URLConnection caches resources with the JAR extension… yay!

/stuff/tree.jpg.jar /stuff/sky.jpg.jar

Cool, didn’t know that either.

From http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLConnection.html#setUseCaches(boolean)

[quote]If the UseCaches flag on a connection is true, the connection is allowed to use whatever caches it can.
[/quote]
It’s a bit vague :slight_smile: Do you know what that usually is for an applet? The browser cache? What are the other possibilities?

I am pretty sure it just uses the HTTP caching method, so the client sends in the header “If-Modified-Since” and if the server accepts it, the caching should work automatically and jar will get re-downloaded when its updated.

I may be off the mark when i say this but from my experience i used the approach… players run the applet on thier computers then if its signed you can create a directory for your game and download what you like into it(images,music etc).my sprites were massive 10mb each and i didnt want a player to download them every time they ran it. you can check the date of file creation so if its newer then it will download it off the server if not it skips it, of course all this is done in the background at a time when performance doesnt matter.

The whole idea is to make it cache media without signing. Caching it yourself in signed code is trivial.

I seem to recall URLConnection was written by Satan himself.

Cas :slight_smile:

If you mean…

  • It makes a lot of promises.
  • It’s hideous.
  • You shouldn’t depend on it.
  • It will hurt you where it hurts most.
  • It tends to deadlock around Christmas.
  • Every incarnation breaks your heart.
    then: yes.

But… it caches JAR files.

Could something be done like giving the user the option to cache resources, having them click a “YES” button, and as the button is clicked a different (signed) JAR is loaded to do the caching?

Sure, until 6u19 screwed us over.