smartfox.IsConnected is true after OnConnectionLost

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

Moderators: Lapo, Bax

zzc11414
Posts: 59
Joined: 26 Jun 2012, 03:17

smartfox.IsConnected is true after OnConnectionLost

Postby zzc11414 » 02 Feb 2013, 08:13

In my application,I will judge the current connection status. in the function OnConnectionLost,I give a debug smartfox.IsConnected ,It is true! and After the connection is lost(server log display disconnect,and client log also give information that OnConnectionLost is executed). So After the connection is lost , I can't reconnect to server. I have open HRC to 15 seconds.

server:2.5
client :unity c# the newest.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: smartfox.IsConnected is true after OnConnectionLost

Postby rjgtav » 02 Feb 2013, 12:23

Hello,

What is the SFS Unity C# Client Api version you're using?
Please make sure you're using the latest 1.0.6
You can get it from:
http://www.smartfoxserver.com/download/sfs2x#p=updates
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
zzc11414
Posts: 59
Joined: 26 Jun 2012, 03:17

Re: smartfox.IsConnected is true after OnConnectionLost

Postby zzc11414 » 02 Feb 2013, 18:05

rjgtav wrote:Hello,

What is the SFS Unity C# Client Api version you're using?
Please make sure you're using the latest 1.0.6
You can get it from:
http://www.smartfoxserver.com/download/sfs2x#p=updates

It's very strange that the newest Unity C# Client Api version(perhaps version1.0.6, I checked that dll create time:2012.12.29) is wrong (in OnConnectionLost function ,smartFox.IsConnected is true)

but the old version (dll created time:2012.4.9 ) is right(smartFox.IsConnected is false in OnConnectionLost)

now I have to go back to this old version.(server version 2.5 linux 64 bit(cent os 6.3 64 bit),,unity version: 3.5.5)
Micr0mega
Posts: 7
Joined: 23 Aug 2012, 15:23

Re: smartfox.IsConnected is true after OnConnectionLost

Postby Micr0mega » 04 Feb 2013, 09:30

I've made a few posts on this issue, but it seems a tough bug to fix. Or at least to keep fixed, as it was working correctly in client API 1.0.3! So that is what I keep using, luckily I have no great need for the newer versions. Note that with 1.0.3 the CONNECTION_LOST event gets fired twice, so it is possible that the "fix" in that version is actually a side effect (or the other way around).

I have sent ThomasLund a PM about this about 1.5 week ago, but I did not get any reply. If anyone from the team wants to pick it up, I'd be happy to forward the PM, which includes a sample project and long description for your convenience.
zzc11414
Posts: 59
Joined: 26 Jun 2012, 03:17

Re: smartfox.IsConnected is true after OnConnectionLost

Postby zzc11414 » 04 Feb 2013, 15:47

Micr0mega wrote:I've made a few posts on this issue, but it seems a tough bug to fix. Or at least to keep fixed, as it was working correctly in client API 1.0.3! So that is what I keep using, luckily I have no great need for the newer versions. Note that with 1.0.3 the CONNECTION_LOST event gets fired twice, so it is possible that the "fix" in that version is actually a side effect (or the other way around).

I have sent ThomasLund a PM about this about 1.5 week ago, but I did not get any reply. If anyone from the team wants to pick it up, I'd be happy to forward the PM, which includes a sample project and long description for your convenience.

I want it.please email :zhouzhongcheng_sz@163.com

Thanks
Micr0mega
Posts: 7
Joined: 23 Aug 2012, 15:23

Re: smartfox.IsConnected is true after OnConnectionLost

Postby Micr0mega » 04 Feb 2013, 16:51

zzc11414 wrote:I want it.please email :zhouzhongcheng_sz@163.com

Thanks


You realize that the mentioned sample project I created contains the error, not the solution? Seems you already know about the error, right?
zzc11414
Posts: 59
Joined: 26 Jun 2012, 03:17

Re: smartfox.IsConnected is true after OnConnectionLost

Postby zzc11414 » 05 Feb 2013, 03:51

I want to produce your problem,and compare with mine
User avatar
nekokiller
Posts: 24
Joined: 23 Oct 2012, 10:13

Re: smartfox.IsConnected is true after OnConnectionLost

Postby nekokiller » 26 Feb 2013, 08:21

Is there anybody work on Unity crash problem ?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: smartfox.IsConnected is true after OnConnectionLost

Postby Lapo » 26 Feb 2013, 11:44

This looks like a double post. I have already replied to an almost identical issue.
Yes, we filed the problem under our bug database and we're going to release an update.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: smartfox.IsConnected is true after OnConnectionLost

Postby Lapo » 06 Mar 2013, 17:28

UPDATE:
We have a preview release of the Unity API that fixes several issues as discussed in this forums.
Please make sure to download the DLL and try it in your project.

Please let us know if it fixes your problems.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
nekokiller
Posts: 24
Joined: 23 Oct 2012, 10:13

Re: smartfox.IsConnected is true after OnConnectionLost

Postby nekokiller » 07 Mar 2013, 01:57

Hi, Lapo:

Fisrt, Thank you very much!

I have download your SFS2X_CSharp_1.0.9, put the SmartFox2.dll in the Plugins folder, and do testing in my FreezeProblem Unity Project.

Good news is : No Freeze Problem any more ~ I have try lots of times, there is no freeze problem.
And the IsConnected flag is true now ( when connection lost event happened ) , the flag works fine now.


But... there are some other problem happened.

My testing scenario:

step 1. run unity project, do connect to smart fox server, and the connesion will success
step 2. use SmartFoxServer Admin Tool, click 'Kick' button to kick user.
step 3. back to unity , client side got a warning:
TCP SocketLayer: INSIDE HANDLE DISCONNECTION, TCP SOCKET LAYER-----------------------

And my debug log show the connection lost reason :
OnConnectionLost! reason: unknown

The first little problem is : the reason string is 'unknown' now, it was 'kick' in last SmartFox Dll version.
So I can not exactly tell the user what is the real reason for this connect lost event.


step 4. do Connect again from client side:
If I wait for a long time before do connect, the connection will build successful and works fine.
But if I do connect quickly ( after connection lost happened in 1~10 seconds ) , I got this three warnings:

TCPSocketLayer: General error reading data from socket: Read failure at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.TCPSocketLayer.Read () [0x00000] in <filename unknown>:0

General error reading data from socket: Read failure at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.TCPSocketLayer.Read () [0x00000] in <filename unknown>:0 ==> NotSocket

TCPSocketLayer: INSIDE HANDLE DISCONNECTION, TCP SOCKET LAYER---------------------------
UnityEngine.Debug:Log(Object)


step 5: When this three warnings happened, I do Connect again and again, I got this smart fox 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)


Step6: Stop the unity project, and redo Step 1 to Step 3

new Step 4: After connection lost event happened ( kick from server ), do Disconnect() first.
new Step 5: do Connect(), the connection will build successful some times. But some times will got this warning:

A connection attempt is already in progress
UnityEngine.Debug:Log(Object)
SmartFoxClient:onSfsWarnLogged(BaseEvent) (at Assets/Scripts/SmartFoxClient.cs:101)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()



Finally, the testing result of the SFS2X_CSharp_1.0.9 version:
No freeze problem, IsConnected flag works fine.
Some times connection works fine, but some times it throws warning or error in connection.
Do disconnect() when connection lost event happend, this can help the next connection build more successful.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: smartfox.IsConnected is true after OnConnectionLost

Postby Lapo » 07 Mar 2013, 09:16

Thanks, it looks like is yet another threading issue, specific to Unity.
I tested using a .Net application, outside of Unity for ease of debugging and the reconnections work flawlessly.

We'll do more testing inside the Unity editor.
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: smartfox.IsConnected is true after OnConnectionLost

Postby Lapo » 07 Mar 2013, 11:44

UPDATE:
We've done some testing in Unity and update the preview release. At this moment the problem seems fixed.
Please download it from this address and let us know.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
nekokiller
Posts: 24
Joined: 23 Oct 2012, 10:13

Re: smartfox.IsConnected is true after OnConnectionLost

Postby nekokiller » 08 Mar 2013, 01:35

Well~ great !
I just download the latest release, and run testing..
Everything works fine..Connection lost reason is correct.
After be kicked , redo connect() is always get success now.
There is no problem.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: smartfox.IsConnected is true after OnConnectionLost

Postby Lapo » 08 Mar 2013, 08:40

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 22 guests