OnConnectionLost(BaseEvent e)

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Assambra
Posts: 5
Joined: 08 Dec 2022, 09:19

OnConnectionLost(BaseEvent e)

Postby Assambra » 08 Dec 2022, 12:00

Server: On a Linux server, SmartFoxServer 2X Community Edition v2.18 with latest v2.18.3 patch.
Client API: C# 1.7.18 in Unity

What happends: OnConnectionLost(BaseEvent e) paramater reason "unknown". If on the Server max idle time for clients reached and the server disconnects the client.

What should happends: paramater reason = idle;


Example code C#

Code: Select all

private void Start()
{
sf = new SmartFox();
sf.ThreadSafeMode = true;

sf.AddEventListener(SFSEvent.CONNECTION, OnConnection);
sf.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

sf.Connect(serverIP, serverPort);
}

private void Update()
{
sf.ProcessEvents();
}

private void OnConnection(BaseEvent e)
{
if ((bool)e.Params["success"])
{
IsConnected = true;
ServerInfoMessage = "Successfully connected";
}
else
{
IsConnected = false;
ServerInfoMessage = "Connection failed";
}
}

private void OnConnectionLost(BaseEvent e)
{
Debug.Log("Connection was lost, Reason: " + (string)e.Params["reason"]);
}
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: OnConnectionLost(BaseEvent e)

Postby Lapo » 09 Dec 2022, 09:33

Hi,
we're not able to reproduce this issue. Are you sure the cause of the disconnection is actually the idle client?
It sounds like it isn't and the "unknown" reason is due to a different cause of the disconnection.

To double check I would recommend testing the same scenario locally (if you're not already doing it). Online it's much easier to incur in other issues triggering a disconnection.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Assambra
Posts: 5
Joined: 08 Dec 2022, 09:19

Re: OnConnectionLost(BaseEvent e)

Postby Assambra » 09 Dec 2022, 23:24

Some More informations:
It is a "local server environment"
VirtualBox 7.0 for windows with a virtual machine Debian GNU/Linux 11 (bullseye) i connect over private lan ip.

New information in my old post i tought it was "User maximum idle time" this was wrong.
The disconnect raise after the time i setup in the server settings "Session maximum idle time" + around 3sec (the 3sec -> maybe the the time unity needs to start the game and establish a connection).


There are some other general questions about connecting to a zone. Do users connecting to a zone count as ccu users?

I'm thinking about how to manage the login process, character selection and creation, and needed zones and rooms with the Login assistant and signup assistant. Some tutorial mean that the signup assistant should be on a different zone with enable guests access and login with disabled access.

Which is the best course of action here?

General i mean there shouldn't be any idle time in "lobby zones" like login and creation selection, but I don't really want that idle people in the lobby count as CCU.

Some newbie question what the difference between Session maximum idle time and User maximum idle time for waht do i need the the Session maximum idle time?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: OnConnectionLost(BaseEvent e)

Postby Lapo » 10 Dec 2022, 09:41

Hi,
the "Session Maximum Idle Time" indicates how long a connection will last before being shut down, if the client does not proceed with a login request.
After a successful connection the client should immediately send a Login request to join one of the available Zones. By default there's a 20 second timeout which will trigger if the client is sitting idle, rather than logging in.
Normally this is abundantly enough for any client to complete a login request.

There are some other general questions about connecting to a zone. Do users connecting to a zone count as ccu users?

Yes.
In the AdminTool you can see two main values: the total amount of Sessions and total amount of Users.
  • Sessions are connections established
  • Users are clients logged in
There can be more Sessions than Users but not the other way around.

I'm thinking about how to manage the login process, character selection and creation, and needed zones and rooms with the Login assistant and signup assistant. Some tutorial mean that the signup assistant should be on a different zone with enable guests access and login with disabled access.

Which is the best course of action here?

You can use a dedicated "guest" Zone for signing up. When the process is complete the client moves to the actual game Zone where he/she can manage their profiles/avatar settings etc.

Some newbie question what the difference between Session maximum idle time and User maximum idle time for waht do i need the the Session maximum idle time?

I've already explained the Session timer above.
The "User maximum idle time" is the maximum amount of time a logged in client can remain idle (without sending any requests) before it is disconnected from the server. Recommended values are between 3 and 10 minutes.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
Assambra
Posts: 5
Joined: 08 Dec 2022, 09:19

Re: OnConnectionLost(BaseEvent e)

Postby Assambra » 10 Dec 2022, 11:49

First i want to say thank you for your detailed answer.

But back again to the first question it is a normal behaviour that if the Session maximum idle time reached on the the server and disconnects the client because idle and the reason is unknown?
In my understanding it should be return reason idle so that on the client side we can handle it in any way.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: OnConnectionLost(BaseEvent e)

Postby Lapo » 12 Dec 2022, 08:44

Hi,
But back again to the first question it is a normal behaviour that if the Session maximum idle time reached on the the server and disconnects the client because idle and the reason is unknown?

If the client is connected but has not logged in there will be no reason given for the disconnection.
Disconnection reasons are only sent to Users, i.e. connected clients that are logged-in.

In my understanding it should be return reason idle so that on the client side we can handle it in any way.

There is not much you can handle in the above situation.
The client took too much time to send the login request and got disconnected. It's not that the client side logic can perform any "special" operation to get back. All you need to do is restart the connection process and send the login within the required time.

If the required time is not enough for your clients you can configure the "Session idle timer" to a higher value, via the AdminTool > Server Configurator.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 21 guests