Solved

save high score

Posted on 1997-03-20
1
506 Views
Last Modified: 2006-11-17
HOw can I save high score in my applet game ?
0
Comment
Question by:mindtwisted
1 Comment
 
LVL 2

Accepted Solution

by:
majkl earned 200 total points
ID: 1219175
Well. Applet cannot write or read from files, so you have to write another so called middle-ware program, that serves datas.
He sends to applet last high score and if player scores new high score, then send this data back to program, which stores it in the file.
This program is standalone application, which watch specific port for connections. Applet can connect to this program, because applets can connect to computer, from which they were loaded from. So program must run on web machine.
I will give you an example how to make a client, how to make a server is much easier.
 import java.io.*;
import java.net.*;

public  class SocketClient
{
  Socket socket;
  DataInputStream in;
  PrintStream out;
  boolean connected = false ;
 
  public SocketClient( String host, int port) throws IOException
  {
    socket = new Socket(host, port);
    in = new DataInputStream(socket.getInputStream());
    out = new PrintStream (socket.getOutputStream());
    connected = true ;
}

  public void write(String data)
  {
    out.println(data);
 }

  public String read() throws IOException
  {
    return in.readLine();
  }
 
  public void disconnect ()
     {
        if ( connected )
          {
             try
               {
                  in.close();
                  out.close();
               } catch (IOException e) { }
             if ( socket != null )
               {
                  try {socket.close();
                  }
                  catch (Exception e) { }
               }
          }
       in = null;
        out = null;
        socket = null;
        connected = false;
     }
 
 public boolean isConnected () { return connected;}



}
*********************************************
Use it in you code like this:
 try
   {    
    client = new SocketClient("name.of.the.machine",41234);
   }
            catch (IOException e )
if (client != null )
   {
     if ( client.isConnected())
       {
        //lets write something to server
      client.write("HELLO");
       //lets read lines until server closes connection
        while ( ( line = client.get_line()) != null)
                      {
                        System.out.println("GOT : "+line);
                      }
        //lets disconnect
        client.disconnect();

Hope this is the answer ?

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
@SBGen Method 3 38
Java Server Faces parameter pass? 6 39
javap bin 2 29
how to install java on RHEL image on EC2 4 7
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now