Where to send disconnect message?

Hi,

I have a little problem. I am newbie, but i think i already get a sending messages through network with SpiderMonkey. But here is a problem…, where should i send a message about disconnecting player when he is closing window? I need to update the number of players after closing window.

I send a message in destroy method override from SimpleApplication, but it didnt get to the server at all. Dubugger didnt help me, because it went across a methods which i dont know, but it didnt end in MessageListener at server. Every other message is working, so i think i am really missing something with this destroy method.

Also i was trying to use DisconnectMessage which i found in client source code, but server didnt catch too…:frowning:

Can anyone help me please or show me some direction? Thanks…

The proper way to do this is to simply close the connection. The server will see the disconnect. You can also send a message if you need to provide additional disconnect info but otherwise it is unnecessary.

The issue is that if you don’t keep the app from exiting then it is likely that it closes before the message ever got a chance to go over the wire. There is a way to catch that the application wants to close earlier than that but I don’t remember what it is.

Either way, your server should see the connection drop… and you’d want to catch the cases where the client crashed or their internet connection died, etc. anyway.

So it sounds to me like you haven’t registered a connection listener on the server. That’s really where you want to keep track of disconnects.

1 Like

Great, i skiped this part of tutorial somehow, thank you very much… :slight_smile: