<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><br></div><div>Folks,</div><div><br></div><div>In my Java application, I connect to VLC remote interface via socket, send the request (such as play, pause, etc.) and wait for the response. The way I am waiting for the response is shown in the following code:</div><div><br></div><pre class="lang-java prettyprint"><code><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> </span><span class="typ">ReadAvailableTextFromSocket</span><span class="pun">(</span><span class="typ">BufferedReader</span><span class="pln"> input</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">IOException</span><span class="pln"> </span><span
class="pun">{</span><span class="pln"><br> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">input</span><span class="pun">.</span><span class="pln">ready</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br> </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span><span class="pln"><br> </span><span class="pun">}</span><span class="pln"><br> </span><span class="typ">StringBuilder</span><span class="pln"> retVal </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">StringBuilder</span><span class="pun">();</span><span class="pln"><br>
</span><span class="kwd">while</span><span class="pun">(</span><span class="pln">input</span><span class="pun">.</span><span class="pln">ready</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br> </span><span class="kwd">char</span><span class="pln"> ch </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">char</span><span class="pun">)</span><span class="pln"> input</span><span class="pun">.</span><span class="pln">read</span><span class="pun">();</span><span class="pln"><br> retVal</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">ch</span><span class="pun">);</span><span class="pln"><br> </span><span class="pun">}</span><span class="pln"><br> </span><span class="kwd">return</span><span class="pln"> retVal</span><span class="pun">.</span><span
class="pln">toString</span><span class="pun">();</span><span class="pln"><br></span><span class="pun">}<br></span></code></pre>
<div>However, this does not seem to be a reliable way to get the response. VLC and/or network may take time to return the response. As a result, the above routine may just return null string.</div><div><br></div><div>I am wondering if there is a better way to receive the data back from VLC.</div><div><br></div><div>While playing with various commands, I noticed that the last line of the response seem to be the message token + ":"</div><div><br></div><div>Sent: play</div><div>Received: play: returned 0 (no error)</div><div>Sent: add file</div><div>Received: add: returned 0 (no error)</div><div><br></div><div>One idea I had was to read the response until token + ":" is returned as the beginning of the line. Will this work? Does VLC always return this type of response to signal the end?</div><div><br></div><div>Thank you in advance for your help.</div><div><br></div><div>Regards,</div><div>Peter<br></div><div><br></div><div><br></div><br></div></body></html>