Occasionall "Cryptography cannot be initialized before connecting to SmartFoxServer!" in SFSEvent.CONNECTION handler

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Occasionall "Cryptography cannot be initialized before connecting to SmartFoxServer!" in SFSEvent.CONNECTION handler

Postby Jochanan » 14 Oct 2019, 16:04

I have checked our logs and find out, that users are ocasionally getting
InvalidOperationException: Cryptography cannot be initialized before connecting to SmartFoxServer! exception iside SFSEvent.CONNECTION handler. I have checked the forum and it looks like, that this exception is thrown when caling InitCrypto() when IsConnected is set to false.

When i add additionall log, IsConnected property is set to true iside the handler.
What do you think it happened? How can we fix it?

I would only assume, that connection lost have been triggered before CONNECTION has been trigerred. Is it even possible? I thought that the handlers are called in serial manner based on the stacktrace:

Code: Select all

Sfs2X.Util.CryptoInitializerV2..ctor (Sfs2X.SmartFox sfs) (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
Sfs2X.SmartFox.InitCrypto () (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
xxx.Client.ServerConnection.OnConnection (Sfs2X.Core.BaseEvent evt) (at <23c0a572b4f74be0ad98fd09011f4a9d>:0)
Sfs2X.Core.EventDispatcher.DispatchEvent (Sfs2X.Core.BaseEvent evt) (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
Rethrow as Exception: Error dispatching event connection: Cryptography cannot be initialized before connecting to SmartFoxServer!   at Sfs2X.Util.CryptoInitializerV2..ctor (Sfs2X.SmartFox sfs) (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
Sfs2X.SmartFox.InitCrypto () (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
xxx.Client.ServerConnection.OnConnection (Sfs2X.Core.BaseEvent evt) (at <23c0a572b4f74be0ad98fd09011f4a9d>:0)
Sfs2X.Core.EventDispatcher.DispatchEvent (Sfs2X.Core.BaseEvent evt) (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
Sfs2X.Core.EventDispatcher.DispatchEvent (Sfs2X.Core.BaseEvent evt) (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
Sfs2X.SmartFox.ProcessEvents () (at <9bfe5727c1e148feb52fa1397dabf0b5>:0)
xxx.Client.ServerConnection.Update () (at <23c0a572b4f74be0ad98fd09011f4a9d>:0)
User avatar
Lapo
Site Admin
Posts: 21450
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Occasionall "Cryptography cannot be initialized before connecting to SmartFoxServer!" in SFSEvent.CONNECTION handler

Postby Lapo » 15 Oct 2019, 07:06

Hi,
for starters, what client platform is you client?
What API version are you using?

The error you have mentioned ("Cryptography cannot be initialized before connecting to SmartFoxServer")... is thrown when a client is trying to start the encryption handshake without an active socket connection to the server.
This suggests that some client is connecting but probably loosing the connection very quickly and when the InitCrypto call is invoked the API complain about it.

The reasons for this can be multiple but essentially it sounds like the client is having network issues at connection time.
It would be interesting to know from your user's feedback if they can connect successfully with a 2nd attempt.

Unless this is happening very frequently it is expected to see a low % of failed connections (in the range of 0%...5%), especially from mobile devices.
Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: Occasionall "Cryptography cannot be initialized before connecting to SmartFoxServer!" in SFSEvent.CONNECTION handler

Postby Jochanan » 15 Oct 2019, 08:27

So far it is Windows only,
c# API 1.7.12 (Unity3D)

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 7 guests