Questions on Session management and Payment confirmations

I am making a 3D online car game for mobile with unity and have some questions:

  1. If the socket connection is closed in the middle of the match for any reason (accidental or…) can anything be done?

  2. Can you suggest a way to prevent this occurrence?

In my local connection tests, after exiting the game (with the task manager so that the code to close the connection that I put in OnApplicationQuit is not executed), I could see that the session on the server is still 1 (no device is connected!).

In the real world, if a large number of users exit the game, the server still calculates their session! (For some reason, the code to close the user session and disconnect them from the server does not work either).

  1. Is there a way to identify and close the session of people who are not connected?

  2. What is the solution that does not put a lot of pressure on the server and does not require a lot of resources?

  3. Why is the number of Goroutines even when there is no load on the server at least 66 or… this number and not zero? What exactly do they do?

I plan to present my game in a market whose identity structure is different from Google Play: they generate a random string that is the user’s in-app payment confirmation, and we enter a string in the input (before sending the user to pay in-app) and returns the same to us again (after the in-app payment status is determined). That’s all this market does.

  1. I want to have a confirmation for payment within the program of this market on the server. Can Huawei In-App Purchase Validation (or other available) be used for this market with this structure? (This market is unknown and has not been officially released yet). Do you know another way?

  2. Do servers have limited socket connections?

  3. Is there a way to increase the number of socket connections? For example, millions of connections? (Of course, a very strong server should be used)

  1. If the socket connection is closed in the middle of the match for any reason (accidental or…) can anything be done?

Assuming you are using an authoritative match handler, your match logic would need to handle this according to your specific game’s needs. For example, you may wish to simply kick them from the match, or you might want to reserve their spot and let them rejoin when they re-establish a connection.You can see an example of this in action in the Nakama Project Template Match Handler.

  1. Can you suggest a way to prevent this occurrence?

There is nothing we can do to prevent random session disconnects and your match handler logic should be designed to expect this. For example, a user may be travelling by train and pass under a bridge and lose connection momentarily; or their WiFi connection to the router may drop suddenly. These things are out of our control I’m afraid.

  1. Is there a way to identify and close the session of people who are not connected?
  2. What is the solution that does not put a lot of pressure on the server and does not require a lot of resources?

Firstly it’s worth mentioning that Sessions themselves do not really incur any cost in terms of performance, so there is no need to worry about users who are authenticated but do not have an active socket connection and who are perhaps offline. That said, sessions will expire automatically. If you wish to manually disconnect or logout users you can use the session_disconnect and session_logout functions.

Again, if you would like to handle things like player’s leaving a match please see the match handler logic in the Nakama Project Template.

  1. Why is the number of Goroutines even when there is no load on the server at least 66 or… this number and not zero? What exactly do they do?

Unless you have specifically written code that is running Goroutines these will be the internal Goroutines Nakama uses to coordinate things within the server and are nothing to worry about.

  1. I want to have a confirmation for payment within the program of this market on the server. Can Huawei In-App Purchase Validation (or other available) be used for this market with this structure? (This market is unknown and has not been officially released yet). Do you know another way?

Our In-App Purchase Validation functionality is designed to work specifically with Apple, Google and Huawei and will not work with other third-party markets. For this you would need to reference the third-party market’s documentation and write your own IAP validation implementation.

  1. Do servers have limited socket connections?

There is no hard-coded limit on the number of active socket connections, but please be aware that more connections = more demand on the CPU/RAM/DB.

  1. Is there a way to increase the number of socket connections? For example, millions of connections? (Of course, a very strong server should be used)

As mentioned, there is no need to manually increase the number of socket connections. However, if you foresee a need for high CCU then we would recommend running your server on Heroic Cloud.