PDA

View Full Version : [Solved] iOS app: properly login / logout user at connection loss



abeldebeer
05-13-2011, 10:53 AM
Hello,

I am developing an iOS app using ElectroServer. Because of the nature of the platform (mobile device) the connection to the server is less reliable and connection events need to be handled properly. I am now struggling with finding the right design and hope you can assist me. The main problem I am trying to tackle is the situation where a user stays logged in on the server when the connection is lost.

Here's a scenario that describes this situation:

(Note: it's required in this application for the user to always use the same login user name, since it will be logged in a database)

- The user is logged in
- The wireless connection is interrupted
- The user can not send an explicit logout request because there is no connection, obviously
- The wireless connection is restored
- The user can not log in using the same user name, because a user of this name is still logged in on the server
- It is not possible to send a logout request, because this action requires a login

How do I make sure the original user is logged out so I can make a clean login?

Thanks a lot in advance!

Abel.

tcarr
05-13-2011, 12:22 PM
This is easily handled by implementing a LoginEventHandler. See UserNameExists (http://www.electrotank.com/docs/es5/manual/usernameexists.htm)in the manual for details. What this does is check for a user of the same username already logged on, and when there is one, kicks that user off the server so that the new one can log in.

You will have fewer headaches if your client discards its instance of the ElectroServer class, and creates a fresh instantiation for the new connection.

abeldebeer
05-13-2011, 12:37 PM
Aha! Thank you for this guideline. I still have to dive into programming ES server side code, so this will be a nice starting point.

tcarr
05-13-2011, 12:50 PM
If you will be storing usernames and passwords in a database, one of these code examples from ES5.2 will help as well: DatabaseWithJDBI (embedded Derby), DBLoginMySQL (MySQL database), TwoStepLogin (if your server is likely to have thousands of concurrent users this scales better). DBLoginMySQL already has the evict lines implemented, so you should be able to just configure the database settings and deploy the extension without recompiling it.

abeldebeer
05-13-2011, 01:39 PM
Thanks so much, it looks like especially the DBLoginMySQL example will be very helpful in this case!

tcarr
05-13-2011, 01:51 PM
Glad to hear it! I'm going to mark this thread Solved. If you have more questions please start a new thread.