Note that there are some explanatory texts on larger screens.

plurals
  1. POJava trouble with SocketChannel connections
    primarykey
    data
    text
    <p>This is a class assignment, so I need hints more than answers.</p> <p>I have a process running on four virtual linux machines. Each process communicates with two of its neighbors. Each process uses </p> <pre><code>server = ServerSocketChannel.open() server.configureBlocking(false) server.socket().bind(new InetSocketAddress(port)) server.register(selector, SelectionKey.OP_ACCEPT) </code></pre> <p>At startup, process A doesn't try to connect to anyone. Process B does</p> <pre><code>SocketChannel SC = SocketChannel.open() SC.configureBlocking( false ) SC.connect(new INetSocketAddress( A-machine, A-port ) SC.register( selector, SC.validOps()) </code></pre> <p>Process C does the same with B; and D with C.</p> <p>Next, I call selector.select and iterate through any selectedKeys. When I see key.isValid() &amp;&amp; key.isAcceptable() both true, I think a socket is attempting to connect to me and I call </p> <pre><code>SocketChannel client = server.accept() client.configureBlocking(false) client.register(selector, client.validOps() ) </code></pre> <p>When I see key.isValid() &amp;&amp; key.isConnectable() both true, I think a server is available for me to connect to. I call</p> <pre><code>SocketChannel connectingChannel = (SocketChannel)key.channel() connectingChannel.finishConnect() </code></pre> <p>When I see key.isValid() &amp;&amp; key.isReadable(), I read in a message I have received.</p> <p>This process works AS LONG AS I START THE PROCESSES IN ORDER: A, B, C, D. If I only start B, it fails on the finishConnect statement. </p> <p>I read the docs where isConnectable tests whether this key's channel has either finished, or failed to finish, its socket-connection operation. How can isConnectable be true and I get a failure on finishConnect?</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.
    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