Master server design

**Edit: **
Note, the topic is renamed.

Hi guys,

A lazy question :wink:

Before I want to try it out my self, I thought to ask it here first

Is it possible to create connections to multiple servers from the same app?

For example, one connection to the game server and one to the master server at the same time with their own ClientServices, Serializers,…

I mean something like this:

masterClient = Network.connectToServer(masterHost, masterPort);
gameClient = Network.connectToServer(gameHost, gamePort);
1 Like

Separate serializers: not easily. You’d have to have two parts of your app run in their own separate isolated class loaders.

Separate connections, sure. But here is how the conversation usually goes:
Me: “Gee, though, it’s weird that your masterhost would have game objects.”
Other person: “No, I just want to check account info and provide leader boards.”
Me: “Ah, so you are trying to make SpiderMonkey’s real time gaming API into a REST services… ;)”

Can you explain more about what you are trying to do?

2 Likes

I have a use-case for that I guess

A masterserver you connect to every time, that has a list of the game-servers you can connect to ? and from within the game, you can switch server (like half-life did back in the day) - or is that “just” REST?

1 Like

It’s much easier to handle the request/response cycle of a flow like that via a standard REST/web API framework than with SpiderMonkey, where you have to handle the network connection lifecycle manually. For things like this, something like the lightweight Javalin framework may serve you well: https://javalin.io/.

1 Like

Yeah, this is what I had in my mind. Mainly because it is very easy to work with JME RMI and works fine both on desktop and mobiles.

I have not worked with REST before, but thanks for informing me, I am going to search more about it.
I guess I need to use a HttpClient library for it, Yes? In that case, I need to find one that can work both on desktop and mobile.

new URL(“myserver/restMethod”).getContent()

Java already have “connect to a web site” stuff built in. You can get fancier but the basics are already there.

As for REST, things like spring-boot make that super simple also. Annotate your methods with RequestMapping annotations, build it with the spring boot plugin, drop it in a web container.

All of these things are 1000x simpler than wrestling with spider monkey just to get some transactional information.

Edit: and most of the time you can test the REST calls directly from your browser. Either with direct URLs for GET calls or with REST plugins for anything else.

3 Likes

If you need something more than the basic URL fetching @pspeed mentioned, the JDK has had a built in HTTP client built in since JDK 11: https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html.

2 Likes

Thanks so much, guys. Your posts were very informative. I appreciate your help. :slightly_smiling_face:

There is one more thing I am interested to know your idea about. Going one step further the REST, It’s about the technology stack for the master server and providing a browser-based dashboard for doing stuff like registration, deposit wallet, activate the game, get latest news, list of game servers,…

Afaik most web frameworks including Spring use MVC pattern in which one yet needs to deal with Html, JS, CSS, and relevant client-side frameworks like Angular and Vue for the presentation layer.

Seems there is another pattern called Domain-driven design for rapidly developing in which one just writes business logic and the presentation layer is generated dynamically. Sounds very interesting to me. Can be useful for making a dashboard, for example.

And I found Apache Isis one of the free and well-known frameworks for that.

Anybody has used it or has any idea regarding it?

Edit:
btw, I renamed topic to “Master server design” as I thought it is more relevant.

Edit2:
Or can/should I do all those stuff with REST and an in game dashboard (made with Lemur Gui for example) and not use browser?

Personally I’d go for REST as your data API - that way you can represent your data however you like - in-game, on a website, wherever, because ultimately it’s just JSON. You can even implement authentication for users if you want to.

So your layout would be something like:

api.mygame.com - REST
api.mygame.com/news - NEWS endpoint.
api.mygame.com/profile - PROFILE endpoint.
mygame.com - WEBSITE feeding off the API.

So you could have an API endpoint https://api.mygame.com/news that spat out the 10 latest news articles, and so on. Some endpoints could require authentication - which is a fancy way of sending an API key along with the request. The API key is associated with a USER, so if you had an endpoint https://api.mygame.com/profile it would return any user-specific data, etc… (or 403 forbidden if not logged in).

This way you have a data-driven backend that can be represented in any way at all. It’s really handy when it comes to updating front-end GUIs because the data end doesn’t change.

In addition there’s really no issue at all to incorporating your REST API within your game for updating statistics, in-game purchases or whatever. It’s just a very elegant way of dealing with data over multiple platforms and languages. A unification of sorts.

If we look at jMonkeyStore as an example - anyone could create data from its API - or anything - including a SDK.

https://jmonkeystore.com/api/page/top/ - displays the top assets
https://jmonkeystore.com/api/page/38308161-c3cf-4e23-8754-528ca8387c11 - Minie Physics Library

It’s all just JSON that can be integrated anywhere.

3 Likes

Ah, I see. It’s clear now. thank you so much @jayfella :slightly_smiling_face:

1 Like

We went through a similar conversation with @mitm a while back. It might be interesting reading.

[SOLVED] World server design questions simethereal

1 Like

Thanks, going to read that. now that I have a clear understanding of REST, it should be easy for me to understand what is going on there :slightly_smiling_face:

Edit:

btw, this was one of the things that I was completely in dark thinking how should I do, but now it totally makes sense.
Again appreciate your help.

1 Like

This thing requires to deeply understand idea to use it efficiently and it requires to design your whole application in particular way. IMO such things are viable only in enterprise sector.

As I see, what you want are web services (RESTful or not - that’s matter of taste).

Spring MVC approaches to development of web services as it is a private case of MVC. You write POJO (“M”) that describe data you want to transfer between client and server, you write controller - annotated class that calls database and returns POJOs (“C”), but “V”(presentation) part of work is done by fully-automatic JSON [de]serializer.

That’s easy to implement and that doesn’t limit you in other aspects.

Not bad example: https://spring.io/guides/gs/rest-service/

1 Like

Hey @ali,

As was recommended, spring would be something to look into. Their vault server is crazy good. They have both restful and reactive programming. They have a lot of options for pairing to databases built right into their servers.

To get you going,
This leads you into the abyss. It connects to everything spring.
https://spring.io/projects/spring-boot

After you learn rest and reactive programming, use baledung, reactive/restful programming, web flux, in searches and you will find huge amount of data,

This is a complete rest web server with tutorials,

Follow the link at bottom for github repo.

The spring site is where to start though.

Edit: Once you learn the reactive and restful way to program, you can drag the baledung example into the present. Great learning tool.

1 Like

Yeah, for me, if I had my choice of anything for the backend it would be spring-boot talking to mongoDB. I don’t know what the commercial licensing looks like for mongo these days but man it’s just a beautiful database for writing RESTful services (JSON natively… even the query language is json).

And while I often curse some of the hidden magic in spring-boot when things aren’t working right, it really is almost just the right amount of magic. And there is a certain intuitive logic about it that you develop over time.

2 Likes

Spring is so flexible. So many different ways to do whatever you want.

Edit: Thanks for showing me the way. I got lost in it for 8 months.

2 Likes

For the http rest client I am using Retrofit with rxjava adapter to be reactive. For server I am using spring webflux but I haven’t decided completely if I will stay with it. Need to search for alternatives and make sure it is the right fit for me.

2 Likes

Did a brief look into Retrofit and it sounds promising, it’s similar to regular RMI calls.

Regarding the reactive part, I think regular Spring MVC REST + async calls from the client would be enough for my needs, but I might consider it in the future if a need comes.

Thanks :slightly_smiling_face:

Check out AsyncConfigurer.

1 Like

Thanks, @mitm :slightly_smiling_face: