Question

I can connect to a HTTP-Livestream manually by using Sockets like that:

Socket radio = new Socket();
radio.connect(new InetSocketAddress("streaming.fueralle.org", 8000));
PrintWriter out = new PrintWriter(radio.getOutputStream());
out.println("GET /corax.mp3 HTTP/1.0");
out.println("User-Agent: Wget/1.8.2");
out.println("Host: streaming.fueralle.org:8000");
out.println("Accept: */*");
out.println("Connection: Keep-Alive");
out.println("");
out.flush();

DataInputStream is = new DataInputStream(radio.getInputStream());
String headerLine = is.readLine();
while(headerLine.length() > 0){
    resp.getWriter().println("next line is " + headerLine);
    headerLine = is.readLine();
}

Now I have to do this connection with URL and HttpUrlConnection instead (I plan to run it from Google App Engine, which allows no Socket). But I seem to be missing an important bit. If I try a static page like heise.de, it works. But I can not start reading a continuous Stream.

EDIT2: I have put the source (and the whole project) in github, do I miss a big thing? https://github.com/flaschenpost/GoogleAppRadio/blob/master/MGRadio/src/de/gergele/mgradio/MGRadioServlet.java

Here a snippet.

URL u = new URL("http://streaming.fueralle.org:8000/corax.mp3");
// URL u = new URL("http://www.heise.de");
System.out.println("trying to connect!" + u);
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
conn.addRequestProperty("User-Agent", "MGet/1.0.0");
conn.addRequestProperty("Accept", "*/*");
// conn.addRequestProperty("Connection", "Keep-Alive");
// EDIT: I tried with and without setChunkedStreamingMode, I hoped it would 
//       tell the connection-object about the streaming mode from the server
conn.setChunkedStreamingMode(4096);
System.out.println("setup finished..." + conn + " " + conn.getRequestProperties().toString());
System.out.println(" type: " + conn.getContentType());

DataInputStream is = new DataInputStream(conn.getInputStream());

But that leads to an TimeoutException before reading a single character from the headers.

So now my question: Howo can I tune the HTTP-Connection to be as successfull as the Socket-Connection? Do I really have to write my own URLStreamHandlerFactory? Sounds a bit weird...

wget and curl get that stream easily, and I have already spent half a night to find out that Java URL seems to contain to much magic somehow for those livestreams.

Thanks for any help!

Was it helpful?

Solution

You can't use google app engine for live streaming. GAE framework has a time restriction on servlet execution time proof. If you go for background tasks (backend in gae) you will have to pay. And still you'll be only able to save the stream, not to stream it live.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top