How to make a client/server game using Google App Engine
I'm trying to do my first client/server game using Google Apps Engine as my back end (specification requirement.) I've done the tutorials (Java), but that all seems highly browser-centric.
Basically, I'd like my (mobile, 开发者_如何学Pythonnot that it matters) app to:
- Allow the user to create a game-account (NOT their Google account!)
- Log-in with that account.
- Press the "MARCO" button to send an account-identified request to the server.
- Get a "POLO" response from the server.
- As data (like a JSON object, XML-DOM or similar), not as a web-page.
Can anyone point me to a good tutorial/sample project/detailed reading to help me achieve that? I'm pretty sure that, once I get that working, I can do all the rest of it -- but I'm having the "stuck at the starting gate" problem, not being able to work up basic account-login, and non-HTML data exchange.
Thanks!
Unfortunately all of my AppEngine knowledge is using their Python SDK but it "should" translate to Java.
You need to build a user system to start with. I have built a few as a wrapper around the Google account system but if you don't want Google accounts then you can build a simple User table and session system yourself. The concepts are pretty simple but you can see how one is built on top of AppEngine by taking a look here: http://github.com/aht/suas
That example user system has bugs (the cookie stuff) but you won't care as you won't be using cookies. Really you just need the ability to store user accounts, authenticate against those accounts, start a session with an authenticated account, and pass the session key back to the client app. The client app then uses that session key to authenticate in the future. The parts to do most of that can be gleamed from the suas example I gave above.
Once you have the ability to start and authenticate sessions then really you just need the ability to do RPCs to the server from the app. How you initiate the RPC depends on the app platform but when talking to AppEngine you need to talk HTTP. Basically the client will be making HTTP POST requests to the server with the body of the POST being a JSON/XML object containing the session key, the name of the function you wish to call, and any arguments to that function. The response from the server will be a HTTP response with the body of the response being just a JSON/XML object. In Python you can use the simplejson API to convert Python dicts to JSON easily and there is an XML lib that works similarly. There must be an equivalent Java API.
An example of doing RPC requests over HTTP to AppEngine (again in Python, sorry) can be fond here: http://code.google.com/appengine/articles/rpc.html
You can skip all the client stuff unless you are using JavaScript (which is actually a great way to prototype a test client for this). The part you will be interested in is how the server figures out which function to call and how it responds:
self.response.out.write(simplejson.dumps(result))
Hopefully some of that gets you jump started on this project. Good luck!
You may use spring-security for user and session management.
I have used few libraries in my project that will minimize your coding effort at GAE.
1) you can use objectify to minimize the JPA/JDO coding effort
2) use JDOM for creating and parsing xml
3) use JSON google's json JAVA api they have used in google translator wrapper project http://code.google.com/p/google-api-translate-java/
Your mobile app will communicate with your GAE application via HTTP. You should read up on how to process http requests (POST/GET) in GAE. The content of those requests will be in JSON or XML or something easily understood on both sides (not html, as you say yourself).
Allow the user to create a game-account (NOT their Google account!)
Look into app engine database options to store your users data.
Log-in with that account.
Mobile app sends a POST request to GAE, your GAE code verifies username/pwdhash.
Press the "MARCO" button to send an account-identified request to the server.
App engine sessions - check them out. The client gets a cookie if authorization was successful. The cookie is automatically sent with all requests to GAE. This auto-verifies the client session.
Get a "POLO" response from the server.
... respond with HTTP message.
As data (like a JSON object, XML-DOM or similar), not as a web-page.
A web-page response (html) and a JSON response only differ in their headers (Content-Type
) and payload (http character data, json character data). Both can be sent over http.
You can use other clients and not use your own client which will waste your time stupidly. I have researched the internet all over and they do not give specified instructions on how to create a client/server for gaming or anything.
精彩评论