Error in Smartfox object when initial connection fails.

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

Moderators: Lapo, Bax

User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Error in Smartfox object when initial connection fails.

Postby marsoups » 01 Jul 2015, 01:40

There is a situation where if the initial connection fails, and following that an attempt to make a new connection to the server results in an error.

Code: Select all

A real undefined error.System.NullReferenceException: Object reference not set to an instance of an object
  at Sfs2X.Bitswarm.BitSwarmClient.Connect (System.String host, Int32 port) [0x00000] in <filename unknown>:0
  at Sfs2X.SmartFox.Connect (System.String host, Int32 port) [0x00000] in <filename unknown>:0
  at SFS_Connect.Connect () [0x0005c] in


Steps to reproduce :
1. Connect to Smartfox after smartfox object is initialized.

Code: Select all

smartFox.Connect (serverIP, serverPort);

2. Get a failed connection response, eg. connect to invalid or server that is offline or no net connection.

Code: Select all

public void OnConnection(BaseEvent evt) {
      bool success = (bool)evt.Params["success"];

3. Attempt to reconnect, either with a timer or immediate.

Code: Select all

smartFox.Connect (serverIP, serverPort);

4. Observer error with

Code: Select all

               try {
            smartFox.Connect (serverIP, serverPort);
         } catch(Exception exception) {
            Debug.Log(exception);
         }
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Error in Smartfox object when initial connection fails.

Postby Lapo » 01 Jul 2015, 06:05

Hi,
Don't try to reconnect with the same SmartFox instance. Instead create a new object and connect withy that.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
specterdragon
Posts: 9
Joined: 31 Jan 2015, 17:21

Re: Error in Smartfox object when initial connection fails.

Postby specterdragon » 01 Jul 2015, 11:31

Ah... brilliant. I had the same problem but it was low on my priority and hadn't gotten around to fixing it. +1 for good timing and easy advice. :D
User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Re: Error in Smartfox object when initial connection fails.

Postby marsoups » 03 Jul 2015, 02:26

Thanks Lapo, we implemented that as a workaround. It's not ideal and I hope a future update could fix that.

The same needs to be applied for when player loses connection for anyone that may need to know.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Error in Smartfox object when initial connection fails.

Postby Lapo » 03 Jul 2015, 07:03

marsoups wrote:Thanks Lapo, we implemented that as a workaround. It's not ideal and I hope a future update could fix that.

The same needs to be applied for when player loses connection for anyone that may need to know.

Actually we don't have plans to change this approach.
It is simple and effective, the connection can be used for one session and then re-created.

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 31 guests