Note that there are some explanatory texts on larger screens.

plurals
  1. POInterrupting Java DataInputStream readFully()
    primarykey
    data
    text
    <p>I have a Java applet that streams video (MJPEG) from a server. I wrote a proxy server in C# (Windows service) to put between the applet and multiple video servers. A HTML/CSS/Js frontend is used along with the Java applet. All functionality works fine (finally!!!), except one thing. </p> <p>The video server allows you to play back recorded video through a REST interface. When the clip is done, the server leaves the connection open in case you want to send it commands like rewind or seek. The clip is being played fine in the applet until the end. If you try to start a new clip (which entails sending a command from Javscript to the applet), the browser freezes up. However, subsequent commands that would use the same connection work, such as play, pause, and seek. If I stop the windows service, the browser becomes responsive again.</p> <p>This is what I'm <em>assuming</em> is happening: The clip ends (or is paused); no more data is sent but the connection is still active. The applet is waiting on the proxy for the next frame, but the proxy is waiting on the video server for the next frame, which is not going to send any more data.</p> <p>This is the code in a while loop that reads each frame</p> <pre><code>byte[] img = new byte[mContentLength]; inputStream.skipBytes(headerLen); inputStream.readFully(img); </code></pre> <p>I need to interrupt this code somehow.</p> <p>When a new video clip is selected in the HTML frontend, we notify the applet, which calls disconnect() on the CameraStream class. This is that function:</p> <pre><code>// DataInputStream inputStream // HttpURLConnection conn public void disconnect() { System.out.println("disconnect called."); if(running) { running = false; try { // close the socket if(inputStream != null) { inputStream.close(); } if(conn != null) { conn.disconnect(); } inputStream = null; System.out.println("closed."); } catch(Exception ignored) { System.out.println("exc:" + ignored.getMessage()); main.reportErrorFromThrowable(ignored); } } } </code></pre> <p>To test this, I let a quick clip play and run to the end. I then select a new clip. In my Java console, I get the output <code>disconnect called.</code> but I don't get the subsequent <code>closed.</code> message, nor does that generic Exception get caught. When I stop the Windows service, I finally get the <code>closed.</code> message, so it seems like <code>inputStream.close();</code> is blocking.</p> <p>So I guess my question is how can I stop the blocking? Is the <code>readFully(img)</code> call blocking? Or is it the disconnect function (as suggested by the console output I get)?</p> <p><strong>edit:</strong> just to clarify, I wrote the Java applet, HTML, CSS, Javascript, and C# proxy server, so I have access to all of that code. The only code I can't modify is that of the REST interface on the video server.</p> <p><strong>edit2:</strong> i meant to make bounty for this post <a href="https://stackoverflow.com/questions/12219758/proxy-design-pattern">https://stackoverflow.com/questions/12219758/proxy-design-pattern</a></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.
 

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