Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you are mixing client and server logic and you should think about whether you server behaves more like a client. But ok...</p> <p>First of all some java classes as entry point</p> <p><a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/nio/channels/spi/AbstractSelector.html" rel="nofollow">AbstractSelector</a></p> <p><a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/channels/SocketChannel.html" rel="nofollow">SocketChannel</a></p> <p>You can create a new Selector like </p> <pre><code> // Create a new selector Selector socketSelector = SelectorProvider.provider().openSelector(); // Create a new non-blocking server socket channel mServerChannel = ServerSocketChannel.open(); mServerChannel.configureBlocking(false); // Bind the server socket to the specified address and port InetSocketAddress isa = new InetSocketAddress(mHostAddress, mPort); mServerChannel.socket().bind(isa); // Register the server socket channel, indicating an interest in // accepting new connections mServerChannel.register(socketSelector, SelectionKey.OP_ACCEPT); </code></pre> <p>The Selector can wait for inciming client connections</p> <pre><code>// Wait for an event one of the registered channels mSelector.select(); </code></pre> <p>and after a new client was connected, the AbstractSelector can be used to send responses to the client.</p> <pre><code>socketChannel.write(buf); </code></pre> <p>Example code: <a href="http://rox-xmlrpc.sourceforge.net/niotut/" rel="nofollow">http://rox-xmlrpc.sourceforge.net/niotut/</a></p>
    singulars
    1. This table or related slice is empty.
    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. 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