Note that there are some explanatory texts on larger screens.

plurals
  1. POJava TCP/IP: HTTP-Connection to Livestream
    primarykey
    data
    text
    <p>I can connect to a HTTP-Livestream manually by using Sockets like that:</p> <pre><code>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() &gt; 0){ resp.getWriter().println("next line is " + headerLine); headerLine = is.readLine(); } </code></pre> <p>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.</p> <p>EDIT2: I have put the source (and the whole project) in github, do I miss a big thing? <a href="https://github.com/flaschenpost/GoogleAppRadio/blob/master/MGRadio/src/de/gergele/mgradio/MGRadioServlet.java" rel="nofollow">https://github.com/flaschenpost/GoogleAppRadio/blob/master/MGRadio/src/de/gergele/mgradio/MGRadioServlet.java</a></p> <p>Here a snippet.</p> <pre><code>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()); </code></pre> <p>But that leads to an TimeoutException before reading a single character from the headers.</p> <p>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...</p> <p>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.</p> <p>Thanks for any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload