简体   繁体   English

适用于Android应用程序的Java Server

[英]Java Server for Android Application

I need to write a server in java that will store integers that are used as stats for my android app. 我需要用Java编写一个服务器,该服务器将存储用作android应用程序统计信息的整数。 My app has an SQLite database that is already setup that would be useful if I could just pass those contents to the server. 我的应用程序有一个已经建立的SQLite数据库,如果我可以将这些内容传递给服务器,这将非常有用。 I need to do this so that in my multiplayer feature, a player's app will contact the server to know what level their opponent is. 我需要这样做,以便在我的多人游戏功能中,玩家的应用程序将与服务器联系以了解对手的等级。 (This is not real time). (这不是实时的)。 So far I only have a TCP server that opens a client and server socket. 到目前为止,我只有一个打开客户端和服务器套接字的TCP服务器。 Other than that I am not positive what I need to do to make it possible for the server to do what I need. 除此之外,我不太肯定我需要做些什么来使服务器能够完成我需要做的事情。 Anyone have suggestions or good tutorials to help me with my problem? 任何人都有建议或好的教程可以帮助我解决我的问题?

Thanks. 谢谢。

One thing you need to keep track of: 您需要注意的一件事:

Your SQLite DB has to be used as a player session, until the player logs in as another user. 您的SQLite DB必须用作播放器会话,直到播放器以其他用户身份登录。 To do this, you have to have one instance of the current logged in player. 为此,您必须拥有当前登录播放器的一个实例。 If you prefer other methods, here 'sa good list. 如果您喜欢其他方法, 这里是一个不错的清单。

I don't think you would need a TCP connection to view the stats, instead implement a REST API in PHP or any other language for back-end that would save, update and look up for a particular player. 我认为您不需要TCP连接来查看统计信息,而是以PHP或任何其他语言为后端实现REST API,以节省,更新和查找特定播放器。 This is a recommended method. 这是推荐的方法。 If you are familiar with PHP, this tutorial will give you an idea and full details of what I mean. 如果您熟悉PHP,本教程将为您提供我的意思的想法和完整细节。

Indeed, building a server has many methods. 实际上,构建服务器有很多方法。 For example, You can use either socket programming or app-server. 例如,您可以使用套接字编程或应用程序服务器。 If you are familiar with web programming, jsp/php/asp.net, you can communicate between your app and server with HTTP requset, which is easy to do. 如果您熟悉Web编程jsp / php / asp.net,则可以使用HTTP requset在应用程序和服务器之间进行通信,这很容易做到。 To be more specific, someone (neme:abc,password:pwd) logging in with your mutiplayer app, when he or she leaves, send the data to server with HTTP request. 更具体地说,有人(neme:abc,password:pwd)使用您的mutiplayer应用程序登录时,他或她离开时,将数据通过HTTP请求发送到服务器。 Then when he or she logging in with other device, you can get the data from status and continues to play. 然后,当他或她使用其他设备登录时,您可以从状态中获取数据并继续播放。 Of course, you can save the data in local with SharedPrefence in Android, too. 当然,您也可以使用Android中的SharedPrefence将数据保存在本地。 By the way, the apache HTTPClient is recommend when using http connection with server. 顺便说一句,当与服务器使用http连接时,建议使用Apache HTTPClient。

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

相关问题 Android客户端-Java服务器应用程序 - Android Client- Java Server application 通过Android应用程序与Java EE应用程序服务器进行身份验证 - Authentication with a Java EE application server from an Android app 使用同一台ServerSocket服务器的Java,HTML和Android应用程序 - Java, HTML and Android application using the same ServerSocket server Android-Java客户端-服务器-AsyncTask崩溃应用程序中的Toast - Android-Java Client-Server - Toast in AsyncTask crashing application 如何将数据从Android应用程序发送到Java Server(Apache tomcat)? - How to send data from Android application to Java Server(Apache tomcat)? android / ios聊天应用服务器端Java实现 - android/ios chat application server side implementation in java Android应用程序和Java服务器问题。 拒绝连接 - Android Application and Java server issue. Connection refused 如何将数据从Android发送到服务器上的Java应用程序 - How to send data from android to java application on server Android应用程序(客户端)可以使用套接字与Java Web服务器通信吗? - Can an android application(client) communicate with a java web server using sockets? 适用于移动应用程序的Java服务器 - Java server for mobile application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM