当前位置: 首页>>代码示例>>Java>>正文


Java ServerSocketChannel类代码示例

本文整理汇总了Java中io.netty.channel.socket.ServerSocketChannel的典型用法代码示例。如果您正苦于以下问题:Java ServerSocketChannel类的具体用法?Java ServerSocketChannel怎么用?Java ServerSocketChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServerSocketChannel类属于io.netty.channel.socket包,在下文中一共展示了ServerSocketChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: bind

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
 * 启动端口绑定
 * @param local
 * @return
 */
protected final boolean bind(InetSocketAddress local)
{
	boolean isBind=false;
	try {
		log.debug(getName()+"端口绑定中……"+local.toString());
		ChannelFuture cf=doBind(local);
		isBind=cf.channel()!=null && cf.channel().isActive();
		if(isBind)
		{
			log.debug(getName()+"端口绑定成功!"+cf.channel());
			serverCahnel=(ServerSocketChannel) cf.channel();
		}else
		{
			log.debug(getName()+"端口绑定失败!"+cf.channel());
		}
	} catch (Exception e) {
		log.error(e.getMessage(),e);
		throw e;
	}
	return isBind;
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:27,代码来源:AbstractNettyServer.java

示例2: init

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
@Override
public void init(final InetAddress address, final int port, final boolean useEpoll)
{
    final Class<? extends ServerSocketChannel> socketChannelClass;
    final LazyValue<? extends EventLoopGroup> lazyInit;
    if ((Epoll.isAvailable()) && useEpoll)
    {
        socketChannelClass = EpollServerSocketChannel.class;
        lazyInit = this.epollEventLoopGroupLazyValue;
        CoreMain.debug("[Netty] Using epoll channel type");
    }
    else
    {
        socketChannelClass = NioServerSocketChannel.class;
        lazyInit = this.nioEventLoopGroupLazyValue;
        CoreMain.debug("[Netty] Using default channel type");
    }
    this.channelFuture = new ServerBootstrap().channel(socketChannelClass).childHandler(new ServerConnectionChannel(this)).group(lazyInit.get()).localAddress(address, port).bind().syncUninterruptibly();
}
 
开发者ID:Diorite,项目名称:Diorite-old,代码行数:20,代码来源:ServerConnection.java

示例3: startServer

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
protected void startServer() throws InterruptedException {

      ServerBootstrap b = new ServerBootstrap();
      b.group(bossGroup, workerGroup)
       .channel(NioServerSocketChannel.class)
       .handler(new LoggingHandler(LogLevel.INFO))
       .childHandler(new ChannelInitializer<SocketChannel>() {
           @Override
           public void initChannel(SocketChannel ch) throws Exception {
               ChannelPipeline p = ch.pipeline();
               p.addLast(new LoggingHandler(LogLevel.DEBUG));
               p.addLast(new NettySimpleMessageHandler());
               p.addLast(new NettyMasterHandler(DefaultRedisKeeperServer.this, new CommandHandlerManager(), keeperConfig.getTrafficReportIntervalMillis()));
           }
       });
      serverSocketChannel = (ServerSocketChannel) b.bind(currentKeeperMeta.getPort()).sync().channel();
  }
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:18,代码来源:DefaultRedisKeeperServer.java

示例4: ClassLoaderServer

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public ClassLoaderServer(ClassLoader classLoader) throws UnknownHostException, InterruptedException {
    String codeBase = System.getProperty("java.rmi.server.codebase", null);
    if (codeBase == null || codeBase.matches("[0-9]+")) {
        Transport transport = Modules.getInstance().getTransport();
        int port = (codeBase == null) ? 0 : Integer.valueOf(codeBase);
        httpChannel = ClassLoaderServer.run(transport.getAcceptGroup(), transport.getWorkerGroup(), port, classLoader);
        InetSocketAddress inetSocketAddress = ((ServerSocketChannel) httpChannel).localAddress();
        port = inetSocketAddress.getPort();
        String hostName = Modules.getInstance().getConfiguration().getServerHostName();
        if(hostName == null){
            hostName = InetAddress.getLocalHost().getHostName();
        }

        System.setProperty("java.rmi.server.codebase", "http://" + hostName + ":" + port + "/");
        LoaderHandler.loadCodeBaseProperty();
        logger.info("Embedded HTTP server run at {} java.rmi.server.codebase is set to {} ", inetSocketAddress, System.getProperty("java.rmi.server.codebase"));
    } else {
        httpChannel = null;
    }
}
 
开发者ID:barakb,项目名称:asyncrmi,代码行数:21,代码来源:ClassLoaderServer.java

示例5: RpcServer

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
<T extends ServerSocketChannel> RpcServer(EventLoopGroup eventLoopGroup, EventExecutorGroup eventExecutor, Class<T> channel, SocketAddress address) {
    this.address = address;
    this.allChannels = new DefaultChannelGroup(eventLoopGroup.next());
    this.handler = new ServerHandler(allChannels);
    this.bootstrap = new ServerBootstrap();
    bootstrap.channel(channel);
    bootstrap.childHandler(new ServerInitializer(eventExecutor, handler));
    bootstrap.group(eventLoopGroup);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:11,代码来源:RpcServer.java

示例6: getServerSocketChannel

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public static Class<? extends ServerSocketChannel> getServerSocketChannel(){
  if(SUPPORTS_EPOLL){
    return EpollServerSocketChannel.class;
  }else{
    return NioServerSocketChannel.class;
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:8,代码来源:TransportCheck.java

示例7: getServerSocketChannelClass

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public static Class<? extends ServerSocketChannel> getServerSocketChannelClass(EventLoopGroup eventLoopGroup) {
    if (eventLoopGroup instanceof EpollEventLoopGroup) {
        return EpollServerSocketChannel.class;
    } else {
        return NioServerSocketChannel.class;
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:8,代码来源:EventLoopUtil.java

示例8: address

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
 * Return remote address if remote channel {@link NettyContext} otherwise local
 * address if server selector channel.
 *
 * @return remote or local {@link InetSocketAddress}
 */
default InetSocketAddress address(){
	Channel c = channel();
	if (c instanceof SocketChannel) {
		return ((SocketChannel) c).remoteAddress();
	}
	if (c instanceof ServerSocketChannel) {
		return ((ServerSocketChannel) c).localAddress();
	}
	if (c instanceof DatagramChannel) {
		InetSocketAddress a = ((DatagramChannel) c).remoteAddress();
		return a != null ? a : ((DatagramChannel)c ).localAddress();
	}
	throw new IllegalStateException("Does not have an InetSocketAddress");
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:21,代码来源:NettyContext.java

示例9: HttpServer

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
HttpServer(Supplier<EventLoopGroup> eventLoopFactory,
        ServerChannelFactory<ServerSocketChannel> channelFactory,
        ChannelInitializer channelInitializer,
        HttpEventBus eventBus) {
    super(eventLoopFactory, channelFactory, channelInitializer);
    this.eventBus = eventBus;
}
 
开发者ID:bsonntag,项目名称:Neddy,代码行数:8,代码来源:HttpServer.java

示例10: Server

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public Server(Supplier<EventLoopGroup> eventLoopFactory,
        ServerChannelFactory<ServerSocketChannel> channelFactory,
        ChannelInitializer channelInitializer) {
    this.bossGroup = eventLoopFactory.get();
    this.workerGroup = eventLoopFactory.get();
    
    serverBootstrap = new ServerBootstrap()
            .group(bossGroup, workerGroup)
            .channelFactory(channelFactory)
            .childHandler(channelInitializer);
}
 
开发者ID:bsonntag,项目名称:Neddy,代码行数:12,代码来源:Server.java

示例11: isCompatible

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
@Override
protected boolean isCompatible(EventLoop loop) {
    if (!(loop instanceof XnioEventLoop)) {
        return false;
    }
    ServerSocketChannel parent = parent();
    if (parent != null) {
        // if this channel has a parent we need to ensure that both EventLoopGroups are the same for XNIO
        // to be sure it uses a Thread from the correct Worker.
        if (parent.eventLoop().parent() != loop.parent()) {
            return false;
        }
    }
    return true;
}
 
开发者ID:xnio,项目名称:netty-xnio-transport,代码行数:16,代码来源:AbstractXnioSocketChannel.java

示例12: serverSocketChannel

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public static Class<? extends ServerSocketChannel> serverSocketChannel()
{
    return EPOLL ? EpollServerSocketChannel.class : NioServerSocketChannel.class;
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:5,代码来源:NetworkUtils.java

示例13: addLanEndpoint

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
 * Adds a channel that listens on publicly accessible network ports
 */
public void addLanEndpoint(InetAddress address, int port) throws IOException
{
    synchronized (this.endpoints)
    {
        Class <? extends ServerSocketChannel > oclass;
        LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

        if (Epoll.isAvailable() && this.mcServer.func_181035_ah())
        {
            oclass = EpollServerSocketChannel.class;
            lazyloadbase = field_181141_b;
            logger.info("Using epoll channel type");
        }
        else
        {
            oclass = NioServerSocketChannel.class;
            lazyloadbase = eventLoops;
            logger.info("Using default channel type");
        }

        this.endpoints.add(((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>()
        {
            protected void initChannel(Channel p_initChannel_1_) throws Exception
            {
                try
                {
                    p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
                }
                catch (ChannelException var3)
                {
                    ;
                }

                p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"legacy_query", (ChannelHandler)(new PingResponseHandler(NetworkSystem.this))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.CLIENTBOUND)));
                NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
                NetworkSystem.this.networkManagers.add(networkmanager);
                p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
                networkmanager.setNetHandler(new NetHandlerHandshakeTCP(NetworkSystem.this.mcServer, networkmanager));
            }
        }).group((EventLoopGroup)lazyloadbase.getValue()).localAddress(address, port)).bind().syncUninterruptibly());
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:46,代码来源:NetworkSystem.java

示例14: addLanEndpoint

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
 * Adds a channel that listens on publicly accessible network ports
 */
public void addLanEndpoint(InetAddress address, int port) throws IOException
{
    synchronized (this.endpoints)
    {
        Class <? extends ServerSocketChannel > oclass;
        LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

        if (Epoll.isAvailable() && this.mcServer.shouldUseNativeTransport())
        {
            oclass = EpollServerSocketChannel.class;
            lazyloadbase = SERVER_EPOLL_EVENTLOOP;
            LOGGER.info("Using epoll channel type");
        }
        else
        {
            oclass = NioServerSocketChannel.class;
            lazyloadbase = SERVER_NIO_EVENTLOOP;
            LOGGER.info("Using default channel type");
        }

        this.endpoints.add(((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>()
        {
            protected void initChannel(Channel p_initChannel_1_) throws Exception
            {
                try
                {
                    p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
                }
                catch (ChannelException var3)
                {
                    ;
                }

                p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"legacy_query", (ChannelHandler)(new LegacyPingHandler(NetworkSystem.this))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.CLIENTBOUND)));
                NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
                NetworkSystem.this.networkManagers.add(networkmanager);
                p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
                networkmanager.setNetHandler(new NetHandlerHandshakeTCP(NetworkSystem.this.mcServer, networkmanager));
            }
        }).group((EventLoopGroup)lazyloadbase.getValue()).localAddress(address, port)).bind().syncUninterruptibly());
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:46,代码来源:NetworkSystem.java

示例15: addLanEndpoint

import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
 * Adds a channel that listens on publicly accessible network ports
 */
public void addLanEndpoint(InetAddress address, int port) throws IOException
{
    synchronized (this.endpoints)
    {
        Class <? extends ServerSocketChannel > oclass;
        LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

        if (Epoll.isAvailable() && this.mcServer.shouldUseNativeTransport())
        {
            oclass = EpollServerSocketChannel.class;
            lazyloadbase = SERVER_EPOLL_EVENTLOOP;
            LOGGER.info("Using epoll channel type");
        }
        else
        {
            oclass = NioServerSocketChannel.class;
            lazyloadbase = SERVER_NIO_EVENTLOOP;
            LOGGER.info("Using default channel type");
        }

        this.endpoints.add(((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>()
        {
            protected void initChannel(Channel p_initChannel_1_) throws Exception
            {
                try
                {
                    p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
                }
                catch (ChannelException var3)
                {
                    ;
                }

                p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.READ_TIMEOUT))).addLast((String)"legacy_query", (ChannelHandler)(new LegacyPingHandler(NetworkSystem.this))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.CLIENTBOUND)));
                NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
                NetworkSystem.this.networkManagers.add(networkmanager);
                p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
                networkmanager.setNetHandler(new NetHandlerHandshakeTCP(NetworkSystem.this.mcServer, networkmanager));
            }
        }).group((EventLoopGroup)lazyloadbase.getValue()).localAddress(address, port)).bind().syncUninterruptibly());
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:46,代码来源:NetworkSystem.java


注:本文中的io.netty.channel.socket.ServerSocketChannel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。