Package java.nio.channels

Examples of java.nio.channels.ServerSocketChannel.register()


            try
            {
                ssc = ServerSocketChannel.open();
                ssc.configureBlocking( false );
                ssc.socket().bind( req.address, req.backlog );
                ssc.register( selector, SelectionKey.OP_ACCEPT, req );

                channels.put( req.address, ssc );
            }
            catch( IOException e )
            {
View Full Code Here


           
            // and bind.
            socket.bind(localAddress, getBacklog());
           
            // Register the channel within the selector for ACCEPT event
            channel.register(selector, SelectionKey.OP_ACCEPT);
            success = true;
        } finally {
            if (!success) {
                close(channel);
            }
View Full Code Here

                } else {
                    return;
                }
            }
            try {
                final SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
                key.attach(request);
                request.setKey(key);
            } catch (final IOException ex) {
                closeChannel(serverChannel);
                throw new IOReactorException("Failure registering channel " +
View Full Code Here

                ssc.socket().bind( req.address, cfg.getBacklog() );
                if( req.address == null || req.address.getPort() == 0 )
                {
                    req.address = ( InetSocketAddress ) ssc.socket().getLocalSocketAddress();
                }
                ssc.register( selector, SelectionKey.OP_ACCEPT, req );

                synchronized( channels )
                {
                    channels.put( req.address, ssc );
                }
View Full Code Here

                        }
                      }
                      else if (o instanceof ServerSocketChannel)
                      {
                        ServerSocketChannel channel = (ServerSocketChannel)o;
                        channel.register(getSelector(),SelectionKey.OP_ACCEPT);
                      }
                      else if (o instanceof ChangeTask)
                      {
                        ((ChangeTask)o).run();
                      }
View Full Code Here

                            // Is this for this selectset
                            if (_nextSet==_setID)
                            {
                                // bind connections to this select set.
                                SelectionKey cKey = channel.register(_selectSet[_nextSet].getSelector(), SelectionKey.OP_READ);
                                SelectChannelEndPoint endpoint=newEndPoint(channel,_selectSet[_nextSet],cKey);
                                cKey.attach(endpoint);
                                if (endpoint != null)
                                    endpoint.dispatch();
                            }
View Full Code Here

                    return -1;
                }

                // Register the channel
                try {
                    ch.register(loop.selector, 0);
                } catch (ClosedChannelException e) {
                    logger.warn("Failed to register a temporary selector.", e);
                    return -1;
                }
View Full Code Here

        // set the port the server channel will listen to
        serverSocket.bind(new InetSocketAddress(getBind(), getTcpListenPort()));
        // set non-blocking mode for the listening socket
        serverChannel.configureBlocking(false);
        // register the ServerSocketChannel with the Selector
        serverChannel.register(selector, SelectionKey.OP_ACCEPT);
        while (doListen && selector != null) {
            // this may block for a long time, upon return the
            // selected set contains keys of the ready channels
            try {
View Full Code Here

                    return -1;
                }

                // Register the channel
                try {
                    ch.register(loop.selector, 0);
                } catch (ClosedChannelException e) {
                    logger.warn("Failed to register a temporary selector.", e);
                    return -1;
                }
View Full Code Here

            sock_channel.socket().bind(key);

            // 3. Register the selector with all server sockets. 'Key' is attachment, so we get it again on
            //    select(). That way we can associate it with the mappings hashmap to find the corresponding
            //    value
            sock_channel.register(selector, SelectionKey.OP_ACCEPT, key);
        }

        // 4. Start main loop. won't return until CTRL-C'ed       
        loop(selector);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.