简体   繁体   中英

Proper way to maintain client http client-server connection?

I'm trying to build an Android application in which the client authenticating to the server from the application and after the auth the client sends and receives messages from the server. my server is google app engine server so i'm using Http request (doPost) for communication.

the goals I have already completed are:
1. creating client profile.
2. sending to the server profile data
3. storing the profile at the server
4. log-in registered profile from the db at the server
5. sending the client ok message for good auth.

now my question is how do I maintain this connection?
because it is http connection after a minute or two i'm not sure the connection will be timed-out. and doing the auth again include accessing the db again seems wrong.. what is the proper way to do this. code examples or good tutorials will be appreciated.
Thanks.

you can create Http session on server for each client on successful login and for every subsequent request from client just get session already created. Furthermore, you can persist client specific data in session.Here the link http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Session-Tracking.html . Then you can specify timeout in web.xml on server side. Hope this will help

HTTP is not a session-based protocol. Maintaining an open connection is purely an efficiency improvement; it doesn't provide you with any intrinsic way to associate requests with each other, and shouldn't be used as such.

Instead, use cookie-based sessions, as Ganesh suggests.

A solution is to use Https. It has a challenging mechanism to secure a communication channel between a client and a server.

You can also do like the OAuth protocole. On good OAuth, server provides the client with a token that the client has to resend with every request.

There is an android library for OAuth , and pretty sure there is one to integrate at low cost in your server.

Just ideas, I am really not a web specialist :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM