I want to use HttpURLConnection to open a long-living connection to a server via HTTP POST and process streaming data as it comes in. This is for an Android project.
It's unclear to me how to do this with HttpURLConnection. In iOS, NSURLConnection provides an asynchronous mode where a user-implemented callback gets called as new data comes in and is available for parsing.
With the HttpURLConnection in Java, I see there's an available() method that returns the number of bytes that can be read. But, its unclear how I would write a streaming app that opens a connection and reacts as new streaming data becomes available to parse off a DataInputStream.
I would appreciate some input. Does HttpURLConnection or an alternate class in Java support non-blocking, asynchronous processing of HTTP connections?
Thanks
After doing more research, I've confirmed that Java doesn't have any built-in support for asynchronous HTTP. A packaged called Jetty contains a HTTP client with built-in asynchronous HTTP and callbacks. Its available at:
http://wiki.eclipse.org/Jetty/Tutorial/HttpClient
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With