How to communicate with GameLift Server with Java Client


I have a Java Client I am attempting to integrate with GameLift. I am able to use it to search for Active Fleets, Search Game Sessions, Create Game Sessions and Create Player Sessions. I do not know where to go from there. What API or Java method is used to communicate with the Server. I have the example Server setup and running. The example server code is shown here:

The Java code I have written:


AmazonGameLift gameLift = AmazonGameLiftClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withRegion("us-east-2") .build();

DescribeFleetAttributesRequest dfar = new DescribeFleetAttributesRequest(); DescribeFleetAttributesResult describeFleetResult = gameLift.describeFleetAttributes(dfar);

CreateGameSessionRequest cgsRequest = new CreateGameSessionRequest().withFleetId(describeFleetResult.getFleetAttributes().get(0).getFleetId()) .withName("Sim Game") .withMaximumPlayerSessionCount(MAX_PLAYERS);

CreateGameSessionResult cgsResult = this.gameLift.createGameSession(cgsRequest);

byte[] array = new byte[[PLAYER_ID_LENGTH]]; // length is bounded by PLAYER_ID_LENGTH new Random().nextBytes(array); String playerID = new String(array, Charset.forName("UTF-8"));

CreatePlayerSessionRequest cpsRequest = new CreatePlayerSessionRequest().withGameSessionId(cgsResult.getGameSession().getGameSessionId()) .withPlayerId(playerID);

CreatePlayerSessionResult cpsResult = this.gameLift.createPlayerSession(cpsRequest); ////////////////////////////////////////////////////////////////////////////////////////

I am assuming there is a way to communicate using to the Server using some call to cpsResult. My theory is to use cpsResult.getPlayerSession().marshal()

But I do not understand how to use the marshall function. void marshall(ProtocolMarshaller protocolMarshaller) I am also not sure that is even the correct function to use.

If anyone can point me in the right direction to start attempting Server communication I would be very grateful.

asked 2 years ago431 views
1 Answer

You should build user own communication model for you Java client and Game server. The GameLift doesn't cover that area.

There are two ways of using GameLift managed service.

One is using the game build, that you should build your own communication model into the game server application. It doesn't handle game client connection or communication. You also have to integrate your game server with GameLift agent, via GameLift server SDK, which is not support for JAVA currently. You can refer the architecture from following document :

The other is realtime server that you linked. It support client, server communication, and GameLift integration is the server side, and you can use custom node.js script for you own game logic. To use realtime server, you should use realtime client sdk for communicating with the server script. Currently the client sdk is not support in Java environment officially. The architecture of realtime server is in following document:

So if you want to use Java client, you should build you own communication model from the other network library or you should find or implement realtime client sdk that is unofficial.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions