简体   繁体   English

Android客户端-服务器应用程序和Web服务

[英]Android Client-Server App & Web Services

I have a website that I'm wanting to create a Java application for, and while I don't have any experience creating android applications I have a decent amount of Java experience and feel like I should be able to complete this task over some time. 我有一个要为其创建Java应用程序的网站,尽管我没有创建Android应用程序的经验,但是我有相当多的Java经验,并且觉得我应该能够在一段时间内完成此任务。 I'll be making use of the Java.IO package for client-side networking (On the application) and hosting a server using Java. 我将利用Java.IO包进行客户端网络(在应用程序上)并使用Java托管服务器。 This server application will have access to all of the same databases as the website through JDBC. server application将通过JDBC访问与网站相同的所有数据库。 (I'll be hosting it all on the same server.) (我将全部托管在同一台服务器上。)

My question is how to go about handling connections on the android platform, currently I verify a dynamically generated salt with the database salt on every page refresh to prevent session theft. 我的问题是如何在android平台上处理连接,目前我在每次页面刷新时验证数据库生成的动态盐,以防止会话被盗。 I also make sure that the encrypted password and the user-name stored in the session match. 我还确保加密的密码和会话中存储的用户名匹配。

I could theoretically just create a standard server application, using NIO and avoding the whole thread-per-client scenario. 从理论上讲,我可以使用NIO创建一个标准服务器应用程序,并避免整个“每个客户端线程”场景。 The problem is that my website has quite a bit of traffic, and I know the application will too. 问题是我的网站有很多流量,我也知道该应用程序也可以。 So I'm running into issues on how to handle it. 因此,我遇到了有关如何处理它的问题。

If I use a keep-alive TCP connection and store the users basic information in a class data structure (Psuedo example): 如果我使用保持活动的TCP连接并将用户的基本信息存储在类数据结构中(Psuedo示例):

class User {
    int id;
}

Considering all information will be polled from a database and everything is relative to the id of an account, there's no reason to store any excess data into the User class, correct? 考虑到所有信息都将从数据库中轮询,并且所有信息都与帐户的ID有关,因此没有理由将多余的数据存储到User类中,对吗? Just a quick simple lookup tied to the connection to only get data relavent to yourself. 只需进行与连接有关的快速简单查找,即可获取自己的数据。

Should I avoid the use of TCP networking for this? 我应该避免为此使用TCP网络吗? What do you guys think. 你们有什么感想。

On the server side, create REST web services that invoke CRUD operations on the server database, and return the responses to the client as a JSONObject or JSONArray . 在服务器端,创建用于调用服务器数据库上的CRUD操作的REST Web服务,并将响应作为JSONObjectJSONArray返回给客户端。 Android has internal support for JSON parsing, and you can use the Volley library to call the web services. Android内部支持JSON解析,您可以使用Volley库调用Web服务。 Volley is a pretty abstract, high-level HTTP library that makes it very easy to make REST web service calls. Volley是一个非常抽象的高级HTTP库,可以轻松进行REST Web服务调用。 TCP connections are quite low-level and are not generally used in client-server Android apps. TCP连接的级别很低,通常不用于客户端-服务器Android应用程序。 See the Transmitting Network Data tutorial for more on this. 有关更多信息,请参见传输网络数据教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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