multiple requests in a single HttpConnection in android? - android

the Apache guide on Http connections mention that
The overhead of connection handshaking can be significant, especially
for small HTTP messages. One can achieve a much higher data throughput
if open connections can be re-used to execute multiple requests.
What i want to do is, i want to send 20 similar post request (i.e. the same headers), but the data i send with it is pretty small. So with every request i'm sending the same header data again and again.So i'm looking for a workaround.
for eg:
establish a connection(sending and using the header info, ONCE)
send 20 post requests
close the connection.
My Question : Is it, or is it not, possible to achieve that using Android's HttpClient? If Yes, please provide/point me to a lesson/tutorial/example.
Thanks in advance.
PS: i did some research, couldn't quite find anything useful.

— Edited —
I'm sorry I misunderstood your question.
What you want is obviously possible. However, I think it's up to the server side. If you code server then you can control the format of messages between client and server. If not, then perhaps you should follow server's APIs.

Related

Android : what kind of server?

I'm developing an android app where I would like to fetch some data (mostly text) from the internet but not necesseraly from a website! I would like to have a server that allows clients to fetch some text data. What kind of server fits my goals the best? Http or maybe simply tcp? I don't know much about http so I don't know if it matches my goals and/or if it handles well a kind of text "database".
Edit:
A use case could be: people could write comments and send them to the server. Then clients could refresh their app by fetching new comments from the server. Therefore I'M asking what kind of server could best handle services and kind offre database if needed.
I like using NodeJS in combination with ExpressJS for such purposes. This combination allows you to easily work with HTTP/HTTTPS which is allowed by practically every firewall or proxy server. As of the latter reason I recommend you to use HTTP instead of an own protocol. Furhtermore, Java offers the HTTPURLConnection client which is very easy to use. Moreover, securing traffic with TLS (SSL) is very simple. In addition, NodeJS is resource efficient, runs on Windows, Linux and even on OS X.
For getting the text you can use HTTP GET request handled by the get() method of the Express instance.
This compact tutorial helped me to get familiar with Express on NodeJS.
Without knowing what your use-case is it's difficult to make a good recommendation.
With that said you may find something like https://parse.com/ suitable.
They provide an Android sdk and the 'getting started' tutorials will have you up and running in no time at all.

Safe connection between device and server

The app does not use login username/password feature.. assume whatsapp, or viber.
Howe do these devices make a secure connection to the server and fetch the data, in a way, that even someone else, found out the POSTed data and used them, can not get the info ?
I am using HTTP.
It's a PHP server.
This question is kind of open-ended. Secure communication is often device-independent, based on the protocol stack in use.
From lower- to higher-level:
TCP connection: It may implement SSL.
HTTP protocol: It may implement HTTPS.
GET/PUT operations: You may implement reversible encryption on your payload, like Rijndael. This way, if someone actually gets the POST data, it may be unreadable without the proper decrypt function.
Of course you may combine encryption implementations. Just remeber that you may be adding considerable overhead to the whole process.

android and send data to HTTP server

I write app on android which will need to exchange xml data with http server. I wonder what would be the better approach. Send whole file via POST or maybe get all text from file put it on String and then send this String via POST. Is there will be some difference? If yes what is better option?
I would strongly recommend using POST. While sending the file content using GET is theoretically possibly, in some cases you may encounter problems when using URLs over 2000 characters in length. RFC imposes no strict limit, however some clients and servers impose their own limit. Look at this question for more details on this.
With POST this wouldn't apply and you can send (almost) any size data. To send the file, you would still need to read the content of the file and send it as POST parameter though. Again, in reality, most servers will not accept more than just below 2GB, but that's a separate issue.

Fastest Way to send Data from Android to Server?

I want to send image and text data from Android phone to a Server. i am new plz suggest me the best and easy way to do this task. Server is running a java web service and i will be getting the data from server and also sending the data to server. Thanks
As your server is already there, you will have to use protocol it can uderstand - also SOAP, REST or whatever it uses. So no choice for you.
If you are deigning client-server interacton with android application, you may consider network socket communuication which has less overhead as webservices.

Android Application that displays new messages posted on a server

I am looking for reading resources or sample applications that can help me hammer out the following application workflow:
The client application establishes a connection to our server
The client application scans for updates on a regular interval
If an administrator has posted a new message, the new message is displayed in a widget.
I currently have 2 concerns:
I want to ensure that the monitoring service is not a major battery drain.
What is the most secure and simple method to establish the connection to retrieve data?
....There are a lot of suggestions out there... I need to know what method I should be researching over all others. Currently, all options are on the table because I have yet configure our server.
There are a lot of questions here, I'll try to give a succinct answer.
For the infrastructure I would go with HTTP REST calls to retrieve JSON data reprsenting your messages. Here is a decent link about writing an HTTP REST client for android, there are many others online.
For security, I would definitely start with SSL, but if you need to authenticate the requests I would also look at OAuth to secure you remote API.
As far as A, Have you considered using C2DM (aka "push") to trigger the updates? Then there's no client bandwidth beyond what is being used anyways for the Market/GMail/Talk connection. If you need to support Android versions below 2.2 it's not really an option at the moment, though.
Otherwise there's a few good examples of being a good citizen when polling from a widget; Jeff Sharkey's android-sky is probably the oldest, best, and most authoritative.
For B, unless I'm misunderstanding your need it's pretty hard to beat HTTPS; rolling your own "secure" transport over vanilla HTTP or anything lower-level is just asking for a disaster.

Categories

Resources