如何为多人Android应用程序设置Java服务器和数据库 [英] How to go about setting up a Java server and database for a multiplayer Android application

查看:117
本文介绍了如何为多人Android应用程序设置Java服务器和数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一款多人Android游戏,在任何事物和网络上都是绝对的新手。我对C和Java中的套接字编程有一些了解,但据我所知,从Android设备到远程服务器的通信并不那么简单。 基本上,我只是不确定如何设置这个项目的服务器端组件。我被告知要研究框架,但我不确定它们将如何用于我的具体情况。

I want to make a multiplayer Android game and am an absolute novice at anything and everything networking. I have some knowledge of socket programming in C and Java, however from what I understand, it is not that simple when communicating from an Android device to a remote server. Basically, I am just unsure of how to go about setting up server-side components of this project. I've been told to look into frameworks, but am not really sure exactly how they would be used in my particular case.

以下是我的应用程序如何工作以及我希望它如何与服务器通信的细分。每当用户想要登录,创建游戏,移动,检查统计数据等时,客户端应用程序将向服务器发送请求。服务器将从数据库更新或检索信息(以某种方式)并将其发送到客户端。如果玩家要移动,服务器负责进行所有计算,存储游戏状态,并将更新的游戏推送给两个玩家。

Here is a breakdown of how my application works and how I want it to communicate to the server. The client application will send a request to the server whenever a user wants to login, create game, make a move, check statistics, etc. The server will update or retrieve information from a database(somehow) and send it to the client. If the player is to make a move, the server is responsible for doing all calculations, storing the gamestate, and pushing the updated game to both players.

我希望有人可以说明我将如何开始这个。任何信息将不胜感激。谢谢

I was hoping somebody could shed some light on how I would go about starting this. Any information would be greatly appreciated. Thanks

推荐答案

基本上,您希望设置一个Socket Server程序,在您的服务器上侦听来自客户端的连接。你可以通过多种方式实现这一目标,但似乎你想要利用运行服务器端的数据库(如MySQL)来处理登录用户的身份验证等等。既然你说你熟悉了已经使用Java了,Android是基于Java的,我建议你使用Java作为服务器应用程序。要开始考虑的一些事情是:

Essentially you want to set up a Socket Server program listening on your server for connections from the client. You can achieve this through any number of ways, but it seems like you are going to want to tap into a database (such as MySQL) running server side in order to handle authentication of users logging in, etc. Since you say you have familiarity with Java already, and Android is Java based, I would suggest you go with Java for the server application. A few things to look into to get started would be:

Java中的套接字编程:
http://docs.oracle.com/javase/tutorial/networking/sockets/index.html

Socket Programming in Java: http://docs.oracle.com/javase/tutorial/networking/sockets/index.html

Java中的聊天客户端/服务器示例:
http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-c​​lient-server.html

Chat Client/Server Examples in Java here: http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html

另请参阅Oracle网站上的Java JDBC教程(用于将Java与MySQL服务器连接),您可能会发现Android AsyncTask类在您实现Android客户端时会派上用场。最好从纯Java客户端开始,首先使服务器方面工作,然后转移到基于Android的客户端。建立一些代码后,您可以在此处制作更精确的帖子并收集更具体的答案。希望有所帮助,祝你好运。

Also look into Java JDBC tutorials on Oracle's website (for interfacing Java with a MySQL server), and you will likely find that Android AsyncTask class will come in handy when you implement your Android client. It might be better to start with a pure Java client to get the server aspect working first and then move to an Android-based client. Once you establish some code you can make more refined posts here and gather more specific answers. Hope that helps and good luck.

这篇关于如何为多人Android应用程序设置Java服务器和数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆