Note that there are some explanatory texts on larger screens.

plurals
  1. POSelectable Multicast socket (pre 1.7)
    primarykey
    data
    text
    <p>With the advent of NIO most socket types could be "selectable" through the SelectableChannel implementation. Unfortunately the DatagramChannel does not support multicast prior to java 7. Multicast <b>is</b> supported in prior versions via the <code>MulticastSocket</code> class.</p> <p>I want some way to be able to detect that there are pending messages (i.e. readable) messages on a <b>multicast datagram</b> socket. I would like to read until there are no remaining datagrams within the immediate time window. Having received all pending messages, then want to invoke a callback, <b>but not individually or prior to having read all pending messages</b>. </p> <p>Making this simpler, let's assume one socket. In pseudo code:</p> <pre><code>List&lt;Msg&gt; received = new ArrayList&lt;Msg&gt; while (true) { received.clear(); // initial blocking receive data = receive_blocking (socket, datagram) received.add (new Msg(data)); // flush out remaining messages for (boolean receiving = true ; receiving ; ) { // non-blocking if (receive_nonblocking (socket, datagram)) received.add (new Msg(datagram)); else receiving = false; } callback (received); } </code></pre> <p>The question is how to implement <code>receive_nonblocking</code> without NIO 2. I do not need the Selector mechanism, but wondering whether there is some way I can do a non-blocking read(s) or otherwise detect whether there is something pending.</p> <p>I had read that to use the selector, the channels must be created directly as in <code>new DatagramChannel()</code>, rather than acquiring a channel after socket creation. So if am correct, could not use the <code>socket.getChannel()</code> to create a selector post socket creation.</p> <p>Is there any way to do this that doesn't involve JNI or timers, pre java 7?</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