"Session does not support encryption" when reconnecting

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

Moderators: Lapo, Bax

MartinIsla
Posts: 1
Joined: 16 Apr 2019, 20:24

"Session does not support encryption" when reconnecting

Postby MartinIsla » 16 Apr 2019, 20:41

Hello everyone!
We've been using SFS on our next game for a few months now and it's amazing. We've found the answers to every problem we faced so far in this forum so thanks, Lapo!

We're now working on handling kicking for inactivity. When a client is disconnected (SFSEvent.CONNECTION_LOST), it goes back to the log in screen, gets a "You were disconnected for [reason]" window and is allowed to log in again. This works perfectly.

The problem is when the client tries to log in again, it gets no response from the server. No success, no failure. Nothing happens.
We checked the server log and

Code: Select all

java.lang.IllegalStateException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.IllegalStateException
Message: Session does not support encryption: { Id: 90, Type: DEFAULT, Logged: No, IP: 190.1.35.234:51495 }
Sender: { Id: 90, Type: DEFAULT, Logged: No, IP: 190.1.35.234:51495 }
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.protocol.binary.DefaultPacketEncrypter.execute(DefaultPacketEncrypter.java:42)
com.smartfoxserver.v2.protocol.binary.DefaultPacketEncrypter.decrypt(DefaultPacketEncrypter.java:22)
com.smartfoxserver.v2.protocol.binary.BinaryIoHandler.handlePacketData(BinaryIoHandler.java:410)
com.smartfoxserver.v2.protocol.binary.BinaryIoHandler.handleRead(BinaryIoHandler.java:197)
com.smartfoxserver.v2.protocol.SFSIoHandler.onDataRead(SFSIoHandler.java:143)
com.smartfoxserver.bitswarm.core.SocketReader.readTcpData(SocketReader.java:336)
com.smartfoxserver.bitswarm.core.SocketReader.readIncomingSocketData(SocketReader.java:220)
com.smartfoxserver.bitswarm.core.SocketReader.run(SocketReader.java:171)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)


I googled this error a lot and saw it was related to InitCrypto().
This is our code around InitCrypto()

Code: Select all

 public OnConnection(ServerClient client, ConnectionData data) : base(client, data)
        {
            client.AddEventListener(SFSEvent.CONNECTION, Content);
        }


        /**
         * Sends a login request to the server right after the connection.
         */
        protected override void Content(BaseEvent evt)
        {
            bool success = (bool) evt.Params["success"];
            Debug.Log($"Success: {success}");

            if (success)
            {
                Debug.Log("SFS2X API version: " + client.version);
                Debug.Log("Connection mode is: " + client.connectionMode);

#if !UNITY_WEBGL
            // Enable protocol encryption on non-WebGL builds only (WebGL build uses WSS protocol already)
            if (_connectionData.useEncryption)
            {
                Debug.Log("Init crypto");
                client.GetServer().InitCrypto();
            }
            else
            {
                client.SendRequest(new LoginRequest(_connectionData.GetUserName()));
            }
#else
                // Attempt login
                client.SendRequest(new LoginRequest(_connectionData.GetUserName()));
#endif
            }
            else
            {
                Debug.Log("Something went wrong");
                client.Dispose();
            }

        }


The Content() method is never called. I made sure SFSEvent.CONNECTION listener is never removed!

Any ideas? Thanks :)
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: "Session does not support encryption" when reconnecting

Postby Lapo » 17 Apr 2019, 09:27

Hi,
you said the problem happens when the client attempt to reconnect after being kicked, so I assume there's no problem upon first connection/login.

If that's the case I suspect you're not creating a new SmartFox object after the disconnection.
When you get disconnected you should release the previous event listeners and create a new SmartFox object to start a new session.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 118 guests