very basic - about client-server applications - android

I'm very new to this subject.
I try to build an application server that will interact with clients using Android.
Just before I dive into this field and learn everything, I want to know if there is a proof the design will work.
I build on the fact that the server I want to build can function as well as a client.
For example If a user ask the application server for some data, that my server can POST as a client to another server to get the data to be processed and then handed to the user. Can this work?
again, sorry this is very basic, but I didn't find the specific answer to this and I wanted to make sure I'm not building something "in the air".

All the things you want to do are achievable. It is no problem to let the server make requests to another API to provide the answers back to the client if you want to do sth like this:
Client:
myServer.getWeatherData();
MyServer
public List<WeatherData> getWeatherData() {
//call to local weather station api
}

Related

Using ktor and exposed with postgresql for my back end, how should I send my resultrows to my users?

first post.
I am building an android app and the backend (remote server) im using ktor with exposed and hitting a postgresql data base. I am just unsure upon getting my results back from queries how I should attempt to send those back to my user app on android. What would be the right way. To have the user app install exposed library and just send the query results ? format all the results to a json string and blast that? Just dont know what would be ideal.
I haven't really attempted anything yet because I was looking for a "best practices" idea.
Hi and welcome to Stackoverflow.
There is no one "best practice" way to send the data from the server to the client. Noramlly it depends on your use case. However, one common way that I would suggest you use is to create RESTful-API.
This means:
Requests and Responses to/from the server will be serialized to JSON.
Confirm to HTTP verbs semantics (use GET to read data, PUT to update, etc).
Use status code for error handling
Follow the REST API guidelines for best practices (API versioning, end point names, pagination, etc)
To read more about REST API guidelines, this page is useful.
For Ktor, this will mean having a serializer, and then defining your routes. This guide is useful for Ktor.
Although this is not the only way, but it will provide you with enough experience to explore others APIs (Custom API, RPC, SOAP, etc).

Socket.io and node.js example in android

I am new to socket programming i have to use socket.io and node.js to connect with my server host in android so can anyone please just describe me the programming example of how to connect to server in android. And if possible please give some help regarding node.js and socket.io. As i have searched everywhere on google but not able to find out the proper example.
Thanks
You can just have your web service be REST base.
Your Android application can just talk to your web server via REST and receive data json or xml whatever you fancy.
So with node.js you should set up routes.
An example would of a route would be
www.example.com/users via GET post would return a list of users either in JSON/XML
For your android application you need a library, I believe there's a built in one already, to make request for certain routes such as www.example.com/users via GET method and write the logic to expect JSON or XML and parse that.
I just googled this:
Android: https://github.com/koush/ion
As for node.js you just have to build route...
I think is would be better:
websocket api to replace rest api?
It actually invalidate my answers sorry, REST and websocket api are different.
I have no clue what problem exactly you have. But you should break your problems down to small part. And google and search for answer for each smaller part which would make your life easier to google.
Get your webservice up first so that your android software can consume stuff, build a prototype and then build a prototype of android app that consume data from that webservice.

Android - Ruby on Rails - MySQL

I have started working on an Android app for which we need to use MySQL as database and Ruby on Rails for server side code. We will be using SQLLite too on device(will sync both DB as and when required). I searched the web and couldn't find any relevant tutorials/examples which can serve as a base to start with.
I have gone through MySQL and ROR tutorials but still has confusion on connecting Android with ROR.
Can somebody share some relevant tutorials/code snippet which can explain the complete linkage of the technologies. I mean how to send data from Android device to MySQL and vice versa. I know the concept theoretically but not sure how and where to start with.
My sincere apologies for asking such a basic question or if I sound ambiguous but I am a beginner and need to complete this task. Thanks in Anticipation..
Here is a brief overview of what you should know to accomplish your goal. I am not going to go that far into detail, especially since I have never personally used RoR. Note that some of these parts might not relate exactly to RoR, but the general idea behind it still applies. I will leave it up to you to research and figure out how to implement each individual component.
The general flow of everything is as follows:
Android App <==> Network <==> Web Service <==> MySQL
Note the double-edged arrows since data will be flowing in both directions.
The Android App is the client, and the Web Service and MySQL database are located on your Web Server. I only included the Network part for completeness, but you shouldn't have to do anything once the data has been sent onto the network.
A brief overview of each section:
Android App:
The Android App is the client that sends and retrieves data from the Web Server. I am assuming that in your app you are going to allow the user to do some tasks which in essence becomes the data that you want to send to the server at some point.
Take for example, the user should be able to enter his name and favorite animal. Lets say that there is an actual "Submit" button that the user may click. When this "Submit" button is clicked, it should wrap up the data into a proper format to be sent across the network. Two of the most common ones are JSON and XML. Once the data has been formatted properly, you will want to send the data to the server using some type of network protocol such as HTTP. In order to send the data, you of course must have some URL as the target. Lets say the target is www.example.com/webservice.php. This target is our Web Service located on the Web Server.
Once you send the data, the server will respond with some data at which point you can do whatever you want with it. Maybe display it to the user, or stick it in an SQLite database, or even both.
The key thing to remember is that there is no magic going on. Everything I have just described will be implemented in Java code that you will write in your Android Application at some point.
Key Ideas you should research more and figure out how to implement in Java code:
JSON and XML
HTTP in Java
REST and SOAP
Here is an excellent video on possible ways to set up the structure of your Android App.
Make sure that you are doing all network operations in your Android App on a different thread. An easy to use method is an Intent Service.
Web Service:
This is often the most confusing part. A Web Service is simply some entry point for clients attempting to access the Web Server. My explanation here might different slightly when using RoR, but the same idea applies. Notice above that the target URL was www.example.com/webservice.php. The web service is literally the PHP code that exists on the Web Server, called webservice.php. In your Android App, when you send data to the target URL using HTTP, the Web Service code will be executed on the server (and also have access to the data that you sent to it). Inside of your Web Service code, you will basically be extracting the data (which is in some format like JSON), grabbing the necessary parts, and then doing something with it. In this case you will most likely be querying the database. In PHP it is easy to write code that connects and queries a MySQL database that is also running on the server. When the response of the database is retrieved by the Web Server, you can send it back to the Android App. Just as before, remember, there is no magic going on. All of these ideas are implemented by writing some code.
Main ideas to research:
Ruby on Rails web service
How to access a MySQL database using Ruby on Rails
MySQL Database:
This is where you will store the data on the Web Server. I am not going to go that in depth here because this is just going to require you doing a lot of reading up on how to set up a MySQL database on a web server. It is also important that you learn how to create the appropriate queries such as SELECT, INSERT and so forth.
Main Ideas to research:
How to setup a MySQL database on a web server
If you need any clarification, let me know!

Store data in App Engine datastore from an Android app

I have created an AppEngine connected Android application, and I'm trying to modify it to be able to store some user data on the server. I do not know what's the easiest way to do so, because I want it to be as simple as possible. I just want to store some basic data for every user. This data is: Name, Email, and some other Strings. I have created a form in the android side which will allow the user to type all the requested data, but I do not know how to send this information to the GAE server and store it in the datastore. I guess I will have to use a Servlet and some kind of RPC service to call the methods. I'm really lost because it is my first time doing this. I'm not experienced neither in android nor in web apps. I hope you can help me.
Update
Well, maybe I did not explain myself well. The system I've been asked to build consists on a web service that store your personal login credentials for most common sites (facebook, gmail, etc). Using a chrome extension, you ask the server for the credentials on the website you are navigating, and then the server asks to your phone for authorization. It will ask (do you give me permission to send your credentials to "some user"), and you have to ansewer yes or no and then the server will act in consequence. The point is that you have to store your credentials in the server in some way, maybe from the android app (which is what I was trying) or from somewhere else. I will also need authentication.
Pd: I use java for the server side.
Since you already started with AppEngine connected Android application, it makes sense to continue customizing it: App Engine Data Access: Adding Entities and RPC.
Update:
There are of course many ways to exchange data between client and server. The most simple would be a servlet handling GET and POST requests with some query parameters.
Also, most popoular lately is REST:
Android REST client: http://appfulcrum.com/2010/08/20/android-how-to-call-rest-service-using-asynctask/ (try using GSON instead to parse JSON)
Server: use a REST framework. My personal choice is RESTEasy. An example: http://ankiewsky.blogspot.com/2010/08/resteasy-on-googleappengine-corerest.html
Update 2:
The simplest possible way - making/handlin a simple POST request:
Android client - making POST request with parameters: http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient
Server handling POST (or GET) and extracting parameters: http://www.exampledepot.com/egs/javax.servlet/GetReqParam.html
Find and follow thoroughly the Topic Index on this page. Gud luck

android to django - how to authenticate users

I'm trying to get json data from a django view (login required)
into a new android app I'm working on.
I would like to authenticate the user against the django login
and keep the cookie/session for all the django view calls to
get data from the server.
I did some googling but nothing helped me,
even if I guess it should be a quite common task.
Maybe I'm facing the problem from a wrong point of view..
So I'll switch the question to:
how can I do some user authenticated json request/response to a django server?
Any clue?
You have to do as the website expects, and you need to persist the session cookie.
What I did is using XML-RPC to do all the transfers.
Not exactly sure if it's the best way, considering django's xml-rpc support is some kind of a hack.
Here's a very detailed XML-RPC handler for django:
https://code.djangoproject.com/wiki/XML-RPC
then, setup ur client end on android.
When communication is okay. Start writing server end API.
from django.contrib.auth import authenticate
and use this function to do authentication.
Then for sessionId stuff, you need to go to backend db to manually do them: https://docs.djangoproject.com/en/dev/topics/http/sessions/
as u can see, this is why I don't think it's the best way. You can't send httprequest, hence most django build-in functions doesn't work.

Categories

Resources