Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Buzzy's Auto Server!  (Read 1391 times)
0 Members and 1 Guest are viewing this topic.
Offline Buzzyboy
« Posted 2014-04-11 23:41:33 »

http://s000.tinyupload.com/index.php?file_id=02123651561491845336

I spent the last few hours building an automatic server. It makes having shared objects between Client/Server very simple. It also uses reflection to detect changed variables and then sends the updates to everyone else that is connected.

It has some holes as of now, but I thought it was a very interesting idea.
It's not very secure so I wouldn't recommend using it for a real server. But if you need to test a server/client quickly, this can easily facilitate that.

All Objects that are to be shared between the server/clients extend the SharedObject class. Then you call the init class and then you no longer have to worry about sending updates of the variables to the server/clients. It's done automatically for you.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public class Player extends SharedObject {

   private static final long serialVersionUID = 1L;

   public int Health = 20;
   public int Stamina = 10;
   public int Level = 1;

   public Player(String name) {
      this.identity = name;
      this.registerKeys("Health", "Stamina", "Level");
   }

}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public class MyGame implements Runnable {

   private ConnectionToServer server;

   private Player player;

   public MyGame() {
      try {
         System.out.println("Attempting to connect to server.");
         Socket socket = new Socket("localhost", 2240);
         server = new ConnectionToServer(socket);
         System.out.println("Connected to server.");

         String name = JOptionPane.showInputDialog("What's your name?");
         player = new Player(name);
         player.init(server);
      } catch(Exception e) {
         System.out.println("Failed to connect to server.");
      }
   }
}


After calling the registerKeys on Field names, and calling the init(PacketCommunicator) function on a shared object, it's all taken care of for you.

To get it running, just import it into eclipse, and then run 2 applications: 1) MyAutoServer 2) MyGame

Comments would be much appreciated! ^_^

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (39 views)
2014-10-17 03:59:02

Norakomi (30 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (57 views)
2014-10-14 00:39:48

TehJavaDev (58 views)
2014-10-14 00:35:47

TehJavaDev (48 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!