need some ideas on a Java program. (update - almost there!)

NTB

Diamond Member
Mar 26, 2001
5,179
0
0
So I've spent the last few days putting together this nice little game in Java as a semester project, and in the end I was pretty happy with it. Took it to my proffessor today, and he would *not* take it. He insists that the thing be web-based somehow. This wouldn't be a problem - I could just convert it to an applet - if I didn't need file access. I'm using two small files to keep track of the top 10 scores in the game. The security restrictions for Applets don't allow file access like you can do in an application, so now what do I do? Suggestions?

Nate
 

trek

Senior member
Dec 13, 2000
982
0
71
Originally posted by: NTB
So I've spent the last few days putting together this nice little game in Java as a semester project, and in the end I was pretty happy with it. Took it to my proffessor today, and he would *not* take it. He insists that the thing be web-based somehow. This wouldn't be a problem - I could just convert it to an applet - if I didn't need file access. I'm using two small files to keep track of the top 10 scores in the game. The security restrictions for Applets don't allow file access like you can do in an application, so now what do I do? Suggestions?

Nate

sign the applet with a digital signature, then you will have file access
steps to signing:
keytool ?genkey ?alias <keyname> -keystore <url>
jarsigner ?keystore <url> <jarfile> <keyname>
 

NTB

Diamond Member
Mar 26, 2001
5,179
0
0
Originally posted by: MCrusty
Take out the top 10 scores?

the professor is contradicting himself. Earlier he told me he wanted a program which demonstrated a GUI, file reading / writing, and a few other things, all of which this program does - and then today he springs this on me. I've got until monday to figure something out.

Nate
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
Originally posted by: NTB
Originally posted by: MCrusty
Take out the top 10 scores?

the professor is contradicting himself. Earlier he told me he wanted a program which demonstrated a GUI, file reading / writing, and a few other things, all of which this program does - and then today he springs this on me. I've got until monday to figure something out.

Nate

Add a quick hack of a "Top Scores Server." As long as its running on the same machine as the applet is launched from you don't need any special permissions to access it.

A traditional IO server can be slapped together in under 100 lines of code, and it should only add roughly the same to your existing program. The server component can display file reading/writing and your client can be your nice GUI applet.
 

NTB

Diamond Member
Mar 26, 2001
5,179
0
0
Originally posted by: Kilrsat
Originally posted by: NTB
Originally posted by: MCrusty
Take out the top 10 scores?

the professor is contradicting himself. Earlier he told me he wanted a program which demonstrated a GUI, file reading / writing, and a few other things, all of which this program does - and then today he springs this on me. I've got until monday to figure something out.

Nate

Add a quick hack of a "Top Scores Server." As long as its running on the same machine as the applet is launched from you don't need any special permissions to access it.

A traditional IO server can be slapped together in under 100 lines of code, and it should only add roughly the same to your existing program. The server component can display file reading/writing and your client can be your nice GUI applet.

Sounds simple enough, though I will admit it's not something I've done before. The only server-side stuff I've done with java was a class involving servlets &amp; JSPs, using Tomcat as a "local server" - running on the same machine I was using. Directions or a link about how to do this? (I will look through the books I've got floating around here, as well.)

Nathan.
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
Originally posted by: NTB
Originally posted by: Kilrsat
Originally posted by: NTB
Originally posted by: MCrusty
Take out the top 10 scores?

the professor is contradicting himself. Earlier he told me he wanted a program which demonstrated a GUI, file reading / writing, and a few other things, all of which this program does - and then today he springs this on me. I've got until monday to figure something out.

Nate

Add a quick hack of a "Top Scores Server." As long as its running on the same machine as the applet is launched from you don't need any special permissions to access it.

A traditional IO server can be slapped together in under 100 lines of code, and it should only add roughly the same to your existing program. The server component can display file reading/writing and your client can be your nice GUI applet.

Sounds simple enough, though I will admit it's not something I've done before. The only server-side stuff I've done with java was a class involving servlets &amp; JSPs, using Tomcat as a "local server" - running on the same machine I was using. Directions or a link about how to do this? (I will look through the books I've got floating around here, as well.)

Nathan.
Sun provides one, of course :)

http://java.sun.com/docs/books...kets/clientServer.html
 

NTB

Diamond Member
Mar 26, 2001
5,179
0
0
Originally posted by: Kilrsat
Originally posted by: NTB
Originally posted by: Kilrsat
Originally posted by: NTB
Originally posted by: MCrusty
Take out the top 10 scores?

the professor is contradicting himself. Earlier he told me he wanted a program which demonstrated a GUI, file reading / writing, and a few other things, all of which this program does - and then today he springs this on me. I've got until monday to figure something out.

Nate

Add a quick hack of a "Top Scores Server." As long as its running on the same machine as the applet is launched from you don't need any special permissions to access it.

A traditional IO server can be slapped together in under 100 lines of code, and it should only add roughly the same to your existing program. The server component can display file reading/writing and your client can be your nice GUI applet.

Sounds simple enough, though I will admit it's not something I've done before. The only server-side stuff I've done with java was a class involving servlets &amp; JSPs, using Tomcat as a "local server" - running on the same machine I was using. Directions or a link about how to do this? (I will look through the books I've got floating around here, as well.)

Nathan.
Sun provides one, of course :)

http://java.sun.com/docs/books...kets/clientServer.html

<homer simpson>Do'h</homer simpson>. I should have figured that. I just wasn't awake yet :) Thanks for the link; I will check it out when I get home tonight.

Nate
 

trek

Senior member
Dec 13, 2000
982
0
71
uh, signing the applet is really easy and requires no extra code...
edit: The top score server makes sense if you run it on one computer and are running the game on many other computers.
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
Originally posted by: trek
uh, signing the applet is really easy and requires no extra code...
But signing the applet doesn't provide a logical solution in the "simple user" test.

Since the program is now an applet, launched from a webpage, me the average joe user, wouldn't expect it to save my high scores on my computer. Even if I click "yes" to that security dialog, I really don't expect any web program to start writing stuff to my drive. Especially if its just a neat little game.

I expect it to compare my scores with the scores of everyone else that visits that web page, I expect it not to read/write files from my harddrive, and I expect it to be so neat and cool that I post a link on the internet for all my friends. Then we all play the game for hours and create 150 post threads about how uber l33t we are.

That's what the average user expects when they play a game on a webpage, dumping the stuff locally through a signed applet, that's only signed for the simple reason of trying to break out of the java sandbox, which since you're making an applet you really need to try and develop within, does fit in with the expected behavior.
 

trek

Senior member
Dec 13, 2000
982
0
71
Originally posted by: Kilrsat
Originally posted by: trek
uh, signing the applet is really easy and requires no extra code...
But signing the applet doesn't provide a logical solution in the "simple user" test.

Since the program is now an applet, launched from a webpage, me the average joe user, wouldn't expect it to save my high scores on my computer. Even if I click "yes" to that security dialog, I really don't expect any web program to start writing stuff to my drive. Especially if its just a neat little game.

I expect it to compare my scores with the scores of everyone else that visits that web page, I expect it not to read/write files from my harddrive, and I expect it to be so neat and cool that I post a link on the internet for all my friends. Then we all play the game for hours and create 150 post threads about how uber l33t we are.

That's what the average user expects when they play a game on a webpage, dumping the stuff locally through a signed applet, that's only signed for the simple reason of trying to break out of the java sandbox, which since you're making an applet you really need to try and develop within, does fit in with the expected behavior.

I only brought it up again because of the way you worded your first post
As long as its running on the same machine as the applet is launched from you don't need any special permissions to access it.
If he wants to send the scores to another computer will he have to sign it anyways?
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
Originally posted by: trek
If he wants to send the scores to another computer will he have to sign it anyways?
If the applet attempts a network connection to a machine that isn't the machine the applet came from, then that is another violation of the sandbox, so yes, a signed applet is required there. You can do some interesting things on the server side with a connection forwarder basically acting like a simple proxy.

You trusted the webserver enough to let it launch the applet, so you trust that server enough to talk to it again. You don't trust the rest of the internet, is the basic philosophy behind it all.
 

NTB

Diamond Member
Mar 26, 2001
5,179
0
0
Well, I figured out 2/3s of my problem - I split the rules out into their own .html file, and I figured out how to read the score files *in* so that they can be displayed. The last part is to figure out how to write to a file if any of the scores are beaten. A job for tommorow morning :)

Nate