GameSparks Matchmaking and starting dedicated servers on AWS

Finally after almost a week in both C++ and JavaScript, our game supports matchmaking using GameSparks and dynamically starts new dedicated servers to connect players on our Amazon EC2 instance.

(Thanks to Josh Markiewicz from Epic Games for the high level explanation of Paragon Servers)

(Thanks to Pádraig from GameSparks for Node.js setup)

So how does it all work?

Well first of all I used Node.js to start the UDP server and listen server (not to be confused with UE4 listen server). When the game starts, it will first connect to GameSparks (which will always be successful as long as you have internet connection) and shows you the login screen. When player press the login button it will send a UDP packet (FUDPPing::UDPEcho) to the UDP server created by Node.js on our AWS EC2 instance. It will then sent a reply back to the client and if this message is received game shows the Main Menu screen.

When the player press ready, a matchmaking request is send to GameSparks and GameSparks will do the matchmaking for you. GameSparks offers the powerful Cloud Code that can be used to create custom logic so I modified the MatchFoundMessage Cloud Code and configured it to send a custom message called startDedicatedServer to the first player in participants. In game, I’ve setup a listener that listens to all messages from GameSparks (GameSparksListener component). Messages in GameSparks includes a unique shortcode so whenever GameSparks receives a message I compare the shortcode and if it matches the startDedicatedServer shortcode, the game will send a HTTP request to the Node.Js listen server hosted on AWS EC2 instance with the player ID as a parameter. When this server receive this message it will start our dedicated server with the playerID as commandline. When dedicated server starts it will parse the commandline, retrieves the playerID and connects to GameSparks. When this connection is successful a new LogEventRequest is send using the playerID but this is not a straightforward process. The GameSparks SDK does not offer a way to send Event Request using a playerID but it offers a Node.js sdk that does this. So I created a bat file which runs a javascript file (node.js) and this javascript can parse the commandline to get the values.

So basically from the game I used FPlatform::ExecProcess to run this bat file with playerID and port (GetWorld()->URL.Port) as commandline and the bat file (example bat file: node “C:\Users\YourUserName\Desktop\Send_IP_LogEventRequest.js” %1 %2) will pass these commandlines to javascript, send LogEventRequest (gamesparks.sendAs(playerID)) with the IP of AWS EC2 machine and the port. Again back to GameSparks Cloud Code.

In LogEventRequest Cloud Code, compare the eventKey and send a new message but this time include the IP and Port as the data for this message and then send it.

In our game we receive the above message which includes the proper IP and port which we want to connect to so we simply use open console command to connect to that IP and port and we are done!

About Satheesh (ryanjon2040)

Genuine Unreal Engine user

Posted on June 30, 2016, in Unreal Engine 4 and tagged , , , , , , , , , . Bookmark the permalink. 14 Comments.

  1. Wow this is looking really neat! Glad to be of help 😀


  2. Hahaha I’ve just started researching about integrating Gamesparks and dedicated servers on the cloud. Thank you for posting this!


  3. Hi Satheesh,

    I am current working a iOS multiplayer game with a dedicated server. As you may know ios don’t have a Online Subsystem, so I have to develop matchmaking and listen server myself. And I am working only on this current project, so I need as mush of help as possible.

    Is it possible for you to make a video tutorial about how you accomplished matchmaking with gamesperks?

    Or, is it possible for you to sell or provide the core codes for making this?

    Please help!

    Thank you!


  4. Hi, you did something specific in amazon ec2 or in you game to be able to connect to a dedicated server running on the EC2 instance. For example, I have my EC2 instance running, with a dedicated server process running. I am starting this manually just for tests

    The security group is setup to All Traffic. Then, I just run from my computer my client .exe and type on the command console open and the amazon intance public ip address. But always that give me timeout and i can’t connect to the server.

    Do you have a idea why this is happening ?

    PD: Sorry for my english

    best regards


  5. I did not understand why did you use this method, it is better than another? What makes your project different?


  6. I am really much enjoyed for the info wise that to great technology in this blog. This is interesting info in this website and the nice info in this blog


  7. Thanks a lot for the information you provide.
    But I’m wondering how you can run multiple dedicated servers on one (server) machine and let the player only connect to the dedicated server “assigned” to him. How do you address that? Is every dedicated server bound to a different port so you can select this way which server the client should connect with?
    Would really appreciate any answer 🙂


    • Thanks to Unreal for that actually :). When you start multiple dedicated servers in the same machine each of them are assigned a unique port automatically on startup. That means the first server will have 7777 port (default port of UE) assigned, second one will have 7778, third one 7779 and so on. This information is then send back to all clients so they all connect to the correct server :).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: