OptionalDataException while receiving large files using Apache Mina library on Android - android

I am using Apache Mina to transfer objects between Java server and Android client. I am receiving the following error when transferring large files.
org.apache.mina.filter.codec.ProtocolDecoderException:
org.apache.mina.core.buffer.BufferDataException: java.io.OptionalDataException
(Hexdump: .........)
The same thing works perfectly with just Java client. But on Android I can only receive
small objects. Bigger will throw the exception.
I notice in my logs that Android is processing the object in three pieces. I see
Processing a MESSAGE_RECEIVED for session 1 three times.
Can anybody help me find a workaround/solution for this?

Related

Regarding sending a file to Websocket via android application

I want to upload a mp3 file via Websocket in Android Application.
I was using the external library
http://autobahn.ws/android/
But the problem is that through this library,I cannot upload a big file.say 5 Mb.
I tried researching on similar types of libraries.But could not found a suitable one.
Has anyone tried to upload file on WebSocket in Android Application.
Thanks
As per the mentioned error you are receiving "WebSocketException: frame payload too large", if you go to the source code of the library you are using and search for error you will find out the limitation imposed by the library itself.
// immediately bail out on frame too large
if (payload_len > mOptions.getMaxFramePayloadSize()) {
throw new WebSocketException("frame payload too large");
}
You'll find the this limitation in WebSocketOptions.java
mMaxFramePayloadSize = 128 * 1024;

CURLE_PARTIAL_FILE error for large files with libcurl

I have linked libcurl library (v7.38.0) statically with my C++
application. Using curl, we upload & download files to/from server https. I Have
download fails with the error CURLE_PARTIAL_FILE. This issue occurs
randomly ie., some times the file was downloaded successfully without
issue and some times, the same file fails with the error.
This issue occurs in android platforms. Anyone can show me how to fix that
CURLE_PARTIAL_FILE means that the transfer was aborted before the full contents arrived. That typically means a bad server or a network problem, not a client-side problem.
If you cannot affect the network or server conditions, you probably need to consider ignoring this particular error.

What's the most efficient way to transfer data/packets between native code and Java code in Android

I'm going to write an Android App to read raw packet from native code with raw socket interface. My phone is rooted so my native code can access to the native code by using runtime.exec("su"). But I don't know how to efficient transfer packets between the native code and Java code. (In this case, the native code and Java code are running in different processes) Since my App must process the raw packets from the native code as efficient as possible, I need a "fast tunnel" between them. Any ideas or suggestions?
P.S. I have tired Android NDK, but in NDK, native code and Java code are running in the same process so the native code cannot have the root privilege to access raw socket.
The solution is: create an agent at native layer so that it can talk to your java activity via JNI. Then hook up the agent and your native service by using IPC (binder).
One issue: it is not convenient to pass complex data structure via JNI. So step back, why do you want to pass entire packets? Can you process the packets at native layer and submit the result (e.g., integers) only?

Downloading fails much more frequently on iOS than on Android?

In my iOS project, I use NSURLConnection to download files. My code is just like the http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html document.
In my team's Android project, we use Android's API to download the same files. Nothing special either.
Both the iOS and Android project have the same fail-retry mechanism, and both of them send the same statistic data to server.
The files they trying to download is between 1M to 10M.
The statistic server shows that for the same URL, download failure is 2% on android, but 20% on iOS! Since they are trying to download the same URL, it seems not the server's problem but more like a client issue.
Why iOS download would fail so frequently? Is there any special APIs I should use for iOS, to make the download robust? Currently I'm using NSURLConnection, and I've just found NSURLDownloader which is more convenient to write files. Will they be different for download success percentage?
P.S. the error I got by -
(void) connection: (NSURLConnection *) connection didFailWithError: (NSError *) , is usually -1005, NSURLErrorNetworkConnectionLost.
I'd suggest looking more into why you're getting NSURLErrorNetworkConnectionLost. Even if your device says it's connected, sometimes it could lose the connection and be attempting to regain it before the indicators update accordingly.
This is a good starting point for more information on better dealing with reachability. Checking For Internet Connectivity in Objective C
Otherwise, I recommend you post your download-related code so others can look for possible issues.

Android and Protocol Buffers

I am writing an Android application that would both store data and communicate with a server using protocol buffers. However, the stock implementation of protocol buffers compiled with the LITE flag (in both the JAR library and the generated .java files) has an overhead of ~30 KB, where the program itself is only ~30 KB. In other words, protocol buffers doubled the program size.
Searching online, I found a reference to an Android specific implementation. Unfortunately, there seems to be no documentation for it, and the code generated from the standard .proto file is incompatible with it. Has anyone used it? How do I generate code from a .proto file for this implementation? Are there any other lightweight alternatives?
I know it's not a direct answer to your question, but an extra 30kb doesn't sound that bad to me. Even on EDGE that'll only take an extra 1 to 2 seconds to download. And memory is tight on android, but not THAT tight -- 30 kb is only about 1/10th of one percent of the available application memory space.
Are there any other lightweight alternatives?
I'm taking this to mean "to using protocol buffers", rather than "for using protocol buffers with an Android application". I apologise if you are already commited to protocol buffers.
This site is about "comparing serialization performance and other aspects of serialization libraries on the JVM". You'll find many alternatives listed there.
While there is no mention of the memory footprint of the different implementations at the moment I am sure it is a metric which the people on the wiki would be interested in.
Just to revive this archaic thread for anyone seeing it, the answer is to use Square's Wire library (https://github.com/square/wire)
As they mention themselves:
Wire messages declare public final fields instead of the usual getter methods. This cuts down on both code generated and code executed. Less code is particularly beneficial for Android programs.
They also internally build using the Lite runtime I believe.
And of course Proguard, the new Android 2.0 minify tools, [other generic answers], etc etc.
Use ProGuard[1] on your project. It will reduce the size of jars included in APK file.
[1] http://developer.android.com/guide/developing/tools/proguard.html

Categories

Resources