I have a webservice sending a huge JSON text to an Android app. There's about 20000 ID numbers. Unfortunately but perhaps not surprisingly it's timing out.
What options do I have? The easiest one that comes to mind is somehow compressing this data. Is there any way I can do this (PHP webservice, Java Android app) effectively?
Failing that, is there some technique to send JSON in parts? If so, how does that work? At what point is JSON considered too big to send in one part? Thank you
You can use GZIP in php and send as stream to client and then decode data with java in android
you can use this for gzip in php: GZIP
and Gzip in Android : GZIP
You could compress data with ob_gzhandler(). Put this call in your script before any output:
ob_start('ob_gzhandler');
After that, output will be compressed with gzip.
This is not a good solution, indeed. You should split JSON and send it as sequential smaller pieces. Otherwise, what will you do when even compressed data is too big?
Related
I am developing an app which sends may be like 400kb of data in the interval of every 5seconds ,i have read somewhere that we can conpress the data in php using gz but how to measure the compression and how to deconpress it in java /android .
I have read quite a few posts on stack overflow and it seems gzip can compress streams(ie. I am assuming they mean compress X bytes of the stream at a time). What I don't get is how to do this properly so browsers will decompress it? Let's say I have a 1GB file people need to download and I don't want to bring that all into memory at the same time. How do I compress each chunk and send it on?
closely related question gzip compression of chunked encoding response?
though java code would be great if anyone knows of any. I looked at old playframework 1.2.x code but that doesn't appear to do any compression on writing out chunks :(.
thanks,
Dean
I have an simple understanding question: Why can I only send Binary Data from Android to a FTP server? I am currently learning it and now I understood it. With ByteArrayInputStream I am converting my string into bytes to send it binary. But why binary?
In a digital computer, all data are binary.
Are you talking about a lack of the "ASCII" mode that some FTP clients support? Those have always been problematic in the way they tend to corrupt data. Making an exact copy, without alterations, is a lot safer.
Everything is binary in the computer world.
Is it possible to download large files (>=1Gb) from a servlet to an applet using HttpClient? And what servlet-side lib is useful in this case? Is there another way to approach this?
Any server-side lib that allows you access to the raw output stream should be just fine.
Servlets or JAX-RS for example.
Get the output stream, get the input stream of your file, use a nice big buffer (4k maybe) and pump the bytes from input to output.
On the client side, your applet needs access to the file system. I assume you don't want to keep the 1GB in memory. (maybe we want to stream it to the screen, in which case you don't need elevated access).
Avoid client libraries that try to fully materialize the returned content before handing it to.
Example code here:
Streaming large files in a java servlet
I'm trying write a java program to send live microphone data over UDP, then receive the data in VLC. I'm basically using the same code as in this post to package up the stream and send them over. When I receive the data in VLC, I get nothing. I see a bunch of input coming in but none of it is interpreted as audio data. It tries to resolve the information as mpga or mpgv, but I'm pretty sure it's being sent as raw audio. Is the problem on VLC's end? Should I configure VLC to receive a specific format? Or is the problem with my program not packaging the data in a way VLC can interpret it?
First thing you should do is capture the live microphone data to a file and figure out exactly what format it is. Then transfer the file to VLC (if that makes sense) to see if VLC can cope with it in that form.
If you are going to use UDP in the long term, you need to be sure that the audio format you are using can cope with the loss of chunks of data in the middle of the audio stream due to network packet loss. If not, you should use TCP rather than UDP.