Solved

save high score

Posted on 1997-03-20
1
502 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.

760 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

18 Experts available now in Live!

Get 1:1 Help Now