0

I have written a Java 2D game. It has local and global scores. Local scores were handled, but for global scores, I need to connect to a PHP script.

Script is simply like this:

http://myserver.com/highscore.php?action=submit&name=NAME&score=SCORE&

I can read scores with stream readers, but I can't send new scores to server. I've been looking into outputstreams, but I couldn't handle it.

I also checked this link: http://www.iismarconi.net/inside/materiale/java/tutorial/networking/urls/readingWriting.html

But no dice.

Tanshaydar
  • 28
  • 4

1 Answers1

0

I've solved the issue, and if anyone needs a solution, I'm writing it here:

  HttpURLConnection http = (HttpURLConnection) new URL(highscoreGlobal).openConnection();
  http.setRequestMethod("GET");     //You don't need to set this because HttpURLConnection works with GET in default, but anyway
  http.setReadTimeout( 15*1000);    //Timeout, 15 seconds.
  http.connect();

  BufferedReader reader = new BufferedReader(new InputStreamReader( http.getInputStream()));

And reader.nextLine() will give you the output. In my case, sql query returns 1 if insertion is successful.

Tanshaydar
  • 28
  • 4