Unity WebGL - SFS 2.13 - WebSockets disconnect

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

Moderators: Lapo, Bax

fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 01 Sep 2017, 14:47

Hello,

I'm having a very weird issue with Unity WebGL and SFS 2.13.

I have a android client and a unity webgl client connected to the same room (Game Room). And another WebGl Client connected to the lobby (a separate room).

When a 2nd player is connected to the Game Room, a ScheduleFuture task is started with a periodic tick of 1 second with the help of a TaskScheduler through scheduleAtFixedRate() to countdown the time each player has available to do his actions. After this I send 1 start game message to each of the clients, signaling the game start.

After the match is over, if there are still 2 or more players connected, i try to start another match. If there is A SchedulerFuture task in the loop, from a previous game, i do a .cancel() and start another ScheduleFuture task like mentioned above, and then i send the game start message.

The problem occurs right here: when sending this second game start message after a match has been played. All WebGL clients that are connected to that room when the second start game message is sent are instantly disconnected.

Testing stuff out, i noticed that if i dont cancel() the ScheduleFuture task, the clients are not disconnected, but that causes some unwanted countdowntimer glitches within my room's logic.

I used a remote debug connection with jetty, and set up breakpoints to further identify the cause, stepping into and over code in multiple attempts . Sadly i could only so far down the rabbit hole. I managed to identify line 97 from "com.smartfoxserver.bitswarm.websocket.jetty" as being the line when the webGL clients are dropped right at the "channel.write(rawPacket);" line.

Help? :D

Thanks
Fish.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby Lapo » 02 Sep 2017, 07:34

Hi,
two questions:
1- can it reproduced every time?
2- does it happen locally?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 07:55

1. Yes i can be reproduced everytime.
2. I haven't tested it with a local sfs server. I will try to set one up and test it.

Thanks
fish.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby Lapo » 04 Sep 2017, 08:11

After the match is over, if there are still 2 or more players connected, i try to start another match. If there is A SchedulerFuture task in the loop, from a previous game, i do a .cancel() and start another ScheduleFuture task like mentioned above, and then i send the game start message.

The problem occurs right here: when sending this second game start message after a match has been played. All WebGL clients that are connected to that room when the second start game message is sent are instantly disconnected.

Is the "start message" sent from the new scheduled Task or is it sent in the Extension handler?

Are there any errors on the server and client side when the disconnection occurs?

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 08:24

The start message is sent from the extension handler (i think, i dont know how exactly to check), the message is sent form our extension.jar

The server doesnt record any errors, it just prints the removal of the Webgl client and terminates its session.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby Lapo » 04 Sep 2017, 08:30

So if I understand correctly, you're saying that this "start message" is the cause of disconnection.
However I find it particularly odd because I suppose the same message is used the first time to start the game, right?

I cannot think of a single reason why a message sent from server side should kick everyone out, unless maybe the message was huge in size (e.g. MBytes of data)

My suggestion is to see if the problem can be reproduced in a local setup.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 08:38

Yes, I agree with your that its odd, for the same reason, the same start message is sent first time around.

I will try to reproduce it locally. Will come back with the results.

Thanks
fish.
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 08:47

Side note: It doesnt kick everyone out, just the WebGL clients, Android clients remain connected.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby Lapo » 04 Sep 2017, 09:12

fishbrainz wrote:Side note: It doesnt kick everyone out, just the WebGL clients, Android clients remain connected.

Gotcha. Have you also checked the browser's console when the disconnection happens? To see if there's any detail or error?
I don't think there will any major clue but it still might help to keep an eye on that.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 09:38

I usually test it with 1 browser WebGL client and the Unity Editor set to WebGL platform and both get bet disconnected. SFS Errors listed below.

WebGL client throws
SFS: [SFS > ERROR] [WebSocketLayer] Communication error: Abnormal disconnection.

Unity Editor on WebGL platform throws:
[SFS > ERROR] [WebSocketLayer] Communication error: An exception has occurred while receiving a message. at WebSocketSharp.WebSocketFrame+<ReadAsync>c__AnonStorey1A.<>m__2E (System.Byte[] header) [0x00000] in <filename unknown>:0
at WebSocketSharp.Ext+<ReadBytesAsync>c__AnonStoreyD.<>m__1D (IAsyncResult ar) [0x00000] in <filename unknown>:0
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby Lapo » 04 Sep 2017, 10:07

Thanks.
It would probably be helpful to activate the Debug mode in the SFS API, so that the whole transmission between client and server is captured.

Can you do that and show us the debug?
The parameter is found in the ConfigData object that you pass to Connect() method.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 10:40

The Debug property was set to true, but no additional information was being sent, the only extra information received was through the LogLevel.Info's listener callback, but nothing of value, just the binary stuff. The LogLevel.DEBUG listener was also set but wasnt firing at all.

Do i have to set the sfs server's, and extension's, log4.properties to DEBUG aswel for it the client LogLevel.DEBUG's listener to receive data?
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 10:57

I have tried to get the DEBUG data but i can't seem to figure it out how.

Config.Debug = true
Sfs has the LogLevel.DEBUG listener set with its callback but nothing is firing.
Serverside log4.properties are set to DEBUG

Still, nothing on the client side is receiving extra debug data.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby Lapo » 04 Sep 2017, 13:16

It's not that the client will receive extra debug data. You should find the messages exchanged with the server logged in the browser's console.
Lapo

--

gotoAndPlay()

...addicted to flash games
fishbrainz
Posts: 20
Joined: 30 Aug 2017, 08:30

Re: Unity WebGL - SFS 2.13 - WebSockets disconnect

Postby fishbrainz » 04 Sep 2017, 13:42

Should i see these messages in the console log of unity also?
EDIT: ... if unity is set for the webgl platform, seeing that the editor is being disconnected also?

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 74 guests