Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use the InputStream "available" method </p> <p><a href="http://developer.android.com/reference/java/io/InputStream.html#available%28%29" rel="nofollow noreferrer" title="InputStream&#39;s available&#40;&#41; method">reference page for InputStream</a></p> <p>to check if there is data in the stream before reading without blocking, and check for the elapsed time between reads to decide if a timeout occurred (System.getCurrentTimeMillis() should do the job).</p> <p>Check this answer for reference and a complete listing:</p> <p><a href="https://stackoverflow.com/questions/10522767/implement-a-timeout-in-bluetoothsocket-inputstream-read-in-android">Implement a timeout in BluetoothSocket inputstream.read() in Android</a></p> <p><strong>EDIT:</strong></p> <p>If I'm correctly reading between lines from your comments, you could really use a Bluetooth UDP socket... </p> <p>Sadly <em>it seems</em> that you can't use datagrams with Bluetooth on Android, therefore you have to stick with TCP.</p> <p>If the data you want to send between devices is event driven (e.g. you want the user on device A to receive a notification as soon as the user on device B touches the screen/fires his weapons/etc) you can still adjust your reading loop to do what you want.</p> <p>All you need is a working thread where to put the loop doing the I/O heavy lifting, and a Handler (create it in the UI thread) that will notify some Listener of your choice as soon as you receive anything.</p> <p>Keep in mind that I'm only guessing your usage scenario, so don't get mislead if asynchronous event-driven communication is not the problem.</p> <p>Hope this helps</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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