Client crashing / stuck on connection lost

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

Moderators: Lapo, Bax

vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Client crashing / stuck on connection lost

Postby vkalpias » 11 Jun 2012, 09:05

Hello,

We are using Smartfox and Unity for a multiplayer game. The game is built for the web player. The problem is that if the client loses its connection with the Server then the tab that holds the Unity web player will just hang. The same happens with the Unity editor. If I am playing the game in the editor and the connection with the server is lost ( server is restarted etc ) then Unity hangs and I have to kill its process... I am having a hard time figuring this one out so it'd be great if you could help me out.

Let me know if you have any ideas.

Regards
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Client crashing / stuck on connection lost

Postby rjgtav » 11 Jun 2012, 09:52

Hello.
Are you running the latest Server version (2.1.0) alongside with the latest Unity Client API?
You can find the latest server patch and client API here
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.
vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Re: Client crashing / stuck on connection lost

Postby vkalpias » 11 Jun 2012, 10:23

Hi,

Yes I just downloaded the updates and this is still happening. Note that ( as before ) I do get a connection lost error at the client however the tab or Unity editor still hangs.

Regards
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Client crashing / stuck on connection lost

Postby rjgtav » 11 Jun 2012, 10:32

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.
vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Re: Client crashing / stuck on connection lost

Postby vkalpias » 11 Jun 2012, 10:50

From what I've seen on these other issues you have to call disconnect so that Unity doesn't crash. So in my CONNECTION_LOST listener I now do

Code: Select all

if( server != null && server.IsConnected )
   server.Disconnect();


This seems to fix the problem. I was simply setting server to null beforehand because I assumed that the server would be disconnected after the CONNECTION_LOST event..

Thanks for you help :)
brunoma
Posts: 20
Joined: 11 Jan 2012, 16:36
Location: London, Ontario, Canada

Re: Client crashing / stuck on connection lost

Postby brunoma » 20 Jun 2012, 17:16

We are also getting this issue after upgrading to the latest Unity/C# client (1.0.1) and SmartFoxServer2x (2.0.1)
When the extension reloads and it kicks the users or when the service restarts, we get this error on the client.

Code: Select all

[SMARTFOX] Debug: Admin says: Server is going down or restarting
[SMARTFOX] Debug: Moderator {Server.Mod} says: Extension is reloading
[SMARTFOX] Debug: Connection was lost, Reason: kick
Connection was lost!
[SFS - WARN] TCPSocketLayer: Exception trying to abort socket reader thread
[SFS - ERROR] Error handling data: Thread was being aborted.    at Sfs2X.Core.Sockets.TCPSocketLayer.HandleDisconnection()
   at Sfs2X.Core.Sockets.TCPSocketLayer.Disconnect()
   at Sfs2X.Bitswarm.BitSwarmClient.Disconnect(String reason)
   at Sfs2X.SmartFox.HandleClientDisconnection(String reason)
   at Sfs2X.Controllers.SystemController.FnClientDisconnection(IMessage msg)
   at Sfs2X.Controllers.SystemController.HandleMessage(IMessage message)
   at Sfs2X.Core.SFSProtocolCodec.DispatchRequest(ISFSObject requestObject)
   at Sfs2X.Core.SFSProtocolCodec.OnPacketRead(ByteArray packet)
   at Sfs2X.Core.SFSIOHandler.HandlePacketData(ByteArray data)
[SFS - ERROR] ## SocketDataError: Thread was being aborted.


After that, I am unable to reconnect because IsConnected == true (assuming it never got set to false because of the exception being thrown)
vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Re: Client crashing / stuck on connection lost

Postby vkalpias » 22 Jun 2012, 07:58

Actually we still have a problem with the web player crashing when the connection with the server is lost. Manually calling disconnect in the CONNECTION_LOST listener fixes the problem in the Unity Editor but not on the web player.

Any help would be appreciated because we cannot ship if the client crashes when the connection with the server is lost.

Thank you,
Vaios
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Client crashing / stuck on connection lost

Postby ThomasLund » 03 Jul 2012, 09:58

This might be related to a different issue reported here: viewtopic.php?f=18&t=14345

Will try to fix that one with the workaround suggestions by the Unity guys and then we can see if it also solved this.

Typically some browsers (Firefox being a real bitch) will crash on any kind of thread/exception issues. Safari handles it gracefully.

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Re: Client crashing / stuck on connection lost

Postby vkalpias » 04 Apr 2013, 15:23

Hi there,

The Unity editor still hangs when the connection with the server is lost. This was never fixed for us since Unity 4.. Have you guys had a chance to test this with Unity 4?

Smartfox client: 1.2.0
Smartfox server: 2.5.0
Unity: 4.1.0.f4
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client crashing / stuck on connection lost

Postby Lapo » 08 Apr 2013, 10:42

I have tested with the same setup (api and server), using Unity Editor 4.1.2.
I don't see any problems at all.

I am using the Lobby Example provided with the examples pack, it works as expected under the Editor and the WebPlayer, no crashes or other problems upon disconnection. Tested under MacOSX Lion, Chrome browser.

Maybe the crash is related to something else? Maybe some code in your application?
Are you testing under Windows?

If so please provide all the details so that we can see the problem in action.
Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Re: Client crashing / stuck on connection lost

Postby vkalpias » 08 Apr 2013, 10:52

Hi there,

When a client is connected to the server and we shut the server down, Unity correctly catches the connection lost event. After that when we stop the game and try to start it again Unity hangs.

The same happens in the Unity Web player where if a client is connected, when the server gets shut down the web player will hang when we try to exit the tab.

I have seen this happen before with non-smartfox code and every time it was thread related. Some thread would not be terminated so Unity would not be terminated gracefully. Of course shutting the server down without throwing all clients out beforehand is not something that would happen in the live environment, but it's a problem for development. The same happens when we kick a user using the Smartfox admin panel.

I can show you some code if you want but I doubt you will see anything meaningful as we don't do anything when the connection is lost..

Regards,
Vaios
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client crashing / stuck on connection lost

Postby Lapo » 08 Apr 2013, 11:15

As of API 1.1.0 and subsequent we have ensured that all threads and resources are released promptly upon disconnection.
If I test the scenario that you reported with the latest API all threads are properly shut down upon disconnection.

When a client is connected to the server and we shut the server down, Unity correctly catches the connection lost event. After that when we stop the game and try to start it again Unity hangs.

How? Are you recreating the SmartFox object? That's necessary to start a new Session.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Re: Client crashing / stuck on connection lost

Postby vkalpias » 08 Apr 2013, 11:20

Lapo wrote:How? Are you recreating the SmartFox object? That's necessary to start a new Session.


Yes a new Smartfox object is created. When I say restart the game I mean stopping the Editor by clicking on Unity's Play button and clicking Play again, so everything is recreated.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client crashing / stuck on connection lost

Postby Lapo » 08 Apr 2013, 12:02

If it's not a too big project you can send it via mail to our support@ email box and we'll take a look.
Before you do that just make sure that you're using the latest API version 1.2.0 and please specify which OS are you using (Mac/Win)

Thanks
p.s. = if you send us an email please reference this forum post. thx
Lapo

--

gotoAndPlay()

...addicted to flash games
vkalpias
Posts: 56
Joined: 03 Oct 2011, 09:24

Re: Client crashing / stuck on connection lost

Postby vkalpias » 08 Apr 2013, 12:36

We are using Windows 7 64-bit. Unfortunately I cannot send you the project because it is huge... I will try to reproduce the problem in one of your demos if I can when I have some time and I will let you know ( I have done that in the past and the problem could be reproduced in your demos as well ).

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 23 guests