Author Topic: OnNetworkDisconnect not being called  (Read 3090 times)

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
OnNetworkDisconnect not being called
« on: June 23, 2014, 10:10:11 AM »
Maybe I have overlooked something in the documentation, but is OnNetworkDisconnect supposed to be called in the latest version of TNet? As far as I see, only OnNetworkConnect with the false result argument is actually being called in the event of a client being disconnected from a server, and OnNetworkDisconnect remains inactive no matter the scenario. This is reproduced on AutoJoin example shipped with TNet.

I'm not having any obstacles with that, keeping both connect/disconnect related code under OnNetworkConnect is somewhat convenient even. But I'm curious whether OnNetworkDisconnect was deprecated/deactivated or whether I'm doing something wrong (like, maybe it's only supposed to work on an object with an active TNObject)?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnNetworkDisconnect not being called
« Reply #1 on: June 24, 2014, 07:23:38 AM »
1. I launched TNServer.exe and opened the AutoJoin example.
2. Hit Play, it connects and shows the cubes.
3. Stopped the server ('q', enter) -- error message gets shown about the Main Menu scene not being present, triggered as a result of OnNetworkDisconnect.

OnNetworkConnect gives you the result of your connection attempt. OnNetworkDisconnect gives you a notification telling you that you were connected, but are now disconnected.

FrankYan

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 18
    • View Profile
Re: OnNetworkDisconnect not being called
« Reply #2 on: July 23, 2014, 04:53:51 AM »
OnNetworkDisconnect not being called too~

SimonW

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: OnNetworkDisconnect not being called
« Reply #3 on: August 06, 2014, 05:01:28 AM »
Aren - OnNetworkDisconnect gets called when the server is shut down, but not when the client device loses connection. This is because TNGameClient only calls onDisconnect() when it gets a Disconnect packet. Connection loss is dealt with as an Error packet, which sees that connection state is not Connected and calls onConnect(false) - I think this is a consequence of the way errors are dealt with in the TCP/UDP protocol files. You can test this easily by running the client on a mobile device and turning off the WiFi. Note that OnNetworkConnect(false) only gets called after the timeout, it doesn't seem to notice when the connection drops.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnNetworkDisconnect not being called
« Reply #4 on: August 06, 2014, 08:12:12 PM »
Yup, known and already fixed in the Pro version as of like 3-4 weeks ago. Thanks though. From 1.9.7 version notes:
Quote
1.9.7:
- NEW: TNet is now fully Unity 5-compliant.
- NEW: SendRFC sent to the player's self will now result in immediate execution (think Target.Host).
- NEW: Added better/more informative error messages when RFCs or RCCs fail.
- NEW: TNObject inspector will now show its player owner and whether the player owns this object (at run time).
- FIX: TNManager.JoinChannel will now load the level even without TNManager.
- FIX: TNObjects will now have valid IDs even without TNManager.
- FIX: Added a null check in PrintException for when working with static RCC functions.
- FIX: OnNetworkDisconnect will now be called when the connection is shut down in a non-graceful manner.

SimonW

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: OnNetworkDisconnect not being called
« Reply #5 on: August 07, 2014, 05:09:27 AM »
Excellent, thanks. Any idea when it'll be up on the asset store?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnNetworkDisconnect not being called
« Reply #6 on: August 08, 2014, 06:48:35 AM »
Friday or Saturday night.