Due to the fact that the client and the server must share the same packet classes, I have got the server within the client, like this:
So, I right-click on “PlaneServer.java” and click the “Run File” button to start the server. This works fine, but I would like to export it now so that it can be run remotely, and that clients can still connect.
Obviously, if I click the “build” button, it builds the client.
It would be best to create three separate projects, one with the client, another with the server, and another that has common classes (ie. SpiderMonkey messages). Then, simple add the common project’s output as a dependency of both the server and client. This allows the server and client to only have the classes they need and allows for easier deployment.
I can see your logic, but at the moment I am adding a lot of new messages, and it would be annoying to have to keep re-compiling and re-assigning(?) a dependency. For testing (and alpha) purposes, it will probably be easier for me to just have everything in one large project, due to the fact that I need to change messages and instantly test them, rather than having to wait for compilation, etc.
Thanks for the suggestion though, will consider it in future when the game is more stable.
And just export it with that as the main class… - Thanks, that works perfectly. It’s somewhat awkward, but it will do for the moment. Thanks for the help!
The SDK automatically rebuilds all dependencies that are projects when changed. All you need to do is run the client or server. Also, even without running, the code suggestions fully include all changed files and classes.
Oh right - Cool, I can add a project as a library. I didn’t know that - Was presuming you were suggesting I export it as a JAR and then add it as a file for both projects.
Creating separate projects is the correct answer. We only have 2 projects though, because I have an interface on my messages that allows them to do the majority of handling for themselves in a modular way.
The topic is solved but, just for the record, an other solution is the command line argument.
In the main, check if there is “-server” in arguments. If yes, call the static main method for the server. Otherwise call the static main method for the client.
You can still call directly these methods in your project (they are still valid static main methods).
However it implies that people who will use your program will know how to use a command line (can be solved with a .bat) and it’s why my advice is to set the default mod to “client”, as you can expect that people that want to run a server know a bit more how do such things (they need to open port in firewall etc).