NullReferenceException when connect

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

Moderators: Lapo, Bax

User avatar
nekokiller
Posts: 24
Joined: 23 Oct 2012, 10:13

NullReferenceException when connect

Postby nekokiller » 18 Mar 2013, 02:03

Hi~ Lapo:

I got a NullReferenceException when smart fox do connect().
We want to simulate wifi disconnection because of some unknown problem.


Test 1:

step1: unplug the network line. ( simulation about wifi network disconnecting )
step2: do Connect(), this will get two warnings:

TCPSocketLayer: Connection error: No route to host at System.Net.Sockets.Socket.Connect (System.Net.EndPoint
remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.IPAddress address, Int32 port) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.TCPSocketLayer.ConnectThread () [0x00000] in <filename unknown>:0

Connection error: No route to host at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean
requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.IPAddress address, Int32 port) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.TCPSocketLayer.ConnectThread () [0x00000] in <filename unknown>:0 ==> HostUnreachable


Step3: do Connect() again, then will get this NullReferenceException error:

NullReferenceException: Object reference not set to an instance of an object
Sfs2X.Bitswarm.BitSwarmClient.Connect (System.String ip, Int32 port)
Sfs2X.SmartFox.Connect (System.String host, Int32 port)



Test 2:

Step1: do Connect(), and wait for connection success.
Step2: unplug the network line
Step3: wait for a long time, then do Disconnect();
Step4: do Connect(), will get the NullReferenceException error, too.


ps. smartfox dll: v1.1.0, macOSX: 10.6.8, unity3d: 3.5.7f6
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullReferenceException when connect

Postby Lapo » 18 Mar 2013, 09:00

A few things:

1) Disconnecting the wifi when a connection is already running won't trigger any disconnection events. As we explain in our documentation:

    NOTE: Do not attempt to test the reconnection system by pulling the ethernet cable or shutting down the WIFI connection. Both operations will not terminate your current socket connections and therefore the disconnection event will never be triggered.
http://docs2x.smartfoxserver.com/Develo ... tion-phase
(See last section)

2) Are you sure you are running version 1.1.0. That problem has been fixed in that release and as of now I cannot reproduce it.
It stems from not using the external configuration. Maybe download the API again and make sure to remove the old DLL before adding the new one.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
davidh
Posts: 1
Joined: 11 Mar 2016, 12:47

Re: NullReferenceException when connect

Postby davidh » 11 Mar 2016, 14:19

I get the same NullReferenceException as described above using version 1.6.3 of the DLL in Unity 5.3.3f1.
I am trying to force a failed connection by setting incorrect ports in my configuration.
After the connection has failed I try to connect again and the NullReferenceException appear.
I have noticed that if I do a "new SmartFox()" and work on a new object I can connect again but I would like to avoid this.

NullReferenceException: Object reference not set to an instance of an object
Sfs2X.Bitswarm.BitSwarmClient.Connect (System.String host, Int32 port)
Sfs2X.SmartFox.Connect (System.String host, Int32 port)
Sfs2X.SmartFox.Connect (Sfs2X.Util.ConfigData cfg)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullReferenceException when connect

Postby Lapo » 11 Mar 2016, 14:36

Hi,
davidh wrote:I get the same NullReferenceException as described above using version 1.6.3 of the DLL in Unity 5.3.3f1.
I am trying to force a failed connection by setting incorrect ports in my configuration.
After the connection has failed I try to connect again and the NullReferenceException appear.
I have noticed that if I do a "new SmartFox()" and work on a new object I can connect again but I would like to avoid this.

After a connection has been shut down you will need to recreate the SmartFox object.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
geek_freek
Posts: 2
Joined: 25 Sep 2019, 18:18

Re: NullReferenceException when connect

Postby geek_freek » 01 Jul 2020, 11:50

Hello Everyone,
Is there any way that we can approach this without creating a new session object every time we disconnect. Thanks
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullReferenceException when connect

Postby Lapo » 01 Jul 2020, 13:07

Hi,
sorry no, it is supposed to work this way.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 24 guests