public void start(SlaveNode slaveNode) {
if(slaveNode==null){
throw new IllegalArgumentException("slaveNode is null");
}
EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new SlaveServerInitializer());
ChannelFuture future = b.bind(slaveNode.getPort()).sync();
LOGGER.info("SlaveServer Startup at port:{}",slaveNode.getPort());
// 等待服务端Socket关闭
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
LOGGER.error("InterruptedException:",e);
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
java类io.netty.channel.socket.nio.NioServerSocketChannel的实例源码
SlaveServer.java 文件源码
项目:redant
阅读 29
收藏 0
点赞 0
评论 0
MasterServer.java 文件源码
项目:redant
阅读 27
收藏 0
点赞 0
评论 0
public void start() {
EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new MasterServerInitializer());
ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
LOGGER.info("MasterServer Startup at port:{}",CommonConstants.SERVER_PORT);
// 等待服务端Socket关闭
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
LOGGER.error("InterruptedException:",e);
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
NettyServer.java 文件源码
项目:redant
阅读 27
收藏 0
点赞 0
评论 0
public void start() {
EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ServerInitializer());
ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
logger.info("NettyServer Startup at port:{}",CommonConstants.SERVER_PORT);
// 等待服务端Socket关闭
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
logger.error("InterruptedException:",e);
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
NettyAcceptor.java 文件源码
项目:PetiteRPC
阅读 44
收藏 0
点赞 0
评论 0
@Override
public void bind(int port) {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
ServerBootstrap bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class).localAddress(new InetSocketAddress(8888))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new Encoder(serializer), new Decoder(serializer), new ProviderHandler());
}
});
bootstrap.bind(port);
}
TcpChatServer.java 文件源码
项目:os
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void start() throws Exception {
try {
ServerBootstrap b = new ServerBootstrap()
.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.childHandler(serverInitializer);
logger.info("Starting TcpChatServer... Port: " + port);
channelFuture = b.bind(port).sync();
} finally {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
shutdown();
}
});
}
}
WebSocketChatServer.java 文件源码
项目:os
阅读 67
收藏 0
点赞 0
评论 0
@Override
public void start() throws Exception {
try {
ServerBootstrap b = new ServerBootstrap()
.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.childHandler(serverInitializer);
logger.info("Starting WebSocketChatServer... Port: " + port);
channelFuture = b.bind(port).sync();
} finally {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
shutdown();
}
});
}
}
NettyServer.java 文件源码
项目:webapp-tyust
阅读 29
收藏 0
点赞 0
评论 0
private NettyServer(){
pGroup = new NioEventLoopGroup();
cGroup = new NioEventLoopGroup();
serverBootstrap = new ServerBootstrap();
serverBootstrap.group(pGroup, cGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
//设置日志
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel sc) throws Exception {
sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder());
sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder());
sc.pipeline().addLast(new ReadTimeoutHandler(60));
sc.pipeline().addLast(new NettyServerHandler());
}
});
}
SimpleServer.java 文件源码
项目:upgradeToy
阅读 37
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
.childHandler(new ChannelInitializer<NioSocketChannel>() {
@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
ch.pipeline().addLast(new SimpleServerHandler());
}
});
b.bind(8090).sync().channel().closeFuture().sync();
}
AbstractNettyServer.java 文件源码
项目:Limitart
阅读 35
收藏 0
点赞 0
评论 0
protected AbstractNettyServer(String serverName) {
this.serverName = Objects.requireNonNull(serverName, "server name");
bootstrap = new ServerBootstrap();
if (Epoll.isAvailable()) {
bootstrap.option(ChannelOption.SO_BACKLOG, 1024).channel(EpollServerSocketChannel.class)
.childOption(ChannelOption.SO_LINGER, 0).childOption(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true);
log.info(serverName + " epoll init");
} else {
bootstrap.channel(NioServerSocketChannel.class);
log.info(serverName + " nio init");
}
bootstrap.group(bossGroup, workerGroup).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.childOption(ChannelOption.TCP_NODELAY, true).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
initPipeline(ch.pipeline());
}
});
}
NettyServer.java 文件源码
项目:miracle-remote
阅读 36
收藏 0
点赞 0
评论 0
@Override
public void start(final int port) {
bossGroup = new NioEventLoopGroup(bossGroupThreads);
workerGroup = new NioEventLoopGroup(workerGroupThreads);
ServerBootstrap serverBootstrap = new ServerBootstrap();
try {
serverBootstrap
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, backlogSize)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.TCP_NODELAY, true)
.childHandler(serializeType.getServerChannelInitializer().newInstance());
channel = serverBootstrap.bind(port).sync().channel();
} catch (final Exception ex) {
throw new ServerException(Server.SYSTEM_MESSAGE_ID, ex);
}
}
NettyServer.java 文件源码
项目:mini-dubbo
阅读 31
收藏 0
点赞 0
评论 0
public void doOpen() throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup,workerGroup);
serverBootstrap.channel(NioServerSocketChannel.class);
serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast(new ObjectDecoder(1024*1024, ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())));
pipeline.addLast(new ObjectEncoder());
pipeline.addLast((SimpleChannelInboundHandler)handler);
}
});
serverBootstrap.option(ChannelOption.SO_BACKLOG,1024);
serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE,true);
ChannelFuture future = serverBootstrap.bind(address,port).sync();
//future.channel().closeFuture().sync();
}finally{
//workerGroup.shutdownGracefully();
//bossGroup.shutdownGracefully();
}
}
DefaultServer.java 文件源码
项目:ace
阅读 41
收藏 0
点赞 0
评论 0
/**
* 启动服务
*
* @throws Exception 异常
*/
public void start() throws Exception {
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(channelInitializer)
.option(ChannelOption.SO_BACKLOG, aceServerConfig.getBackSize())
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
ChannelFuture future = bootstrap.bind(aceServerConfig.getPort()).sync();
System.out.println("ace server starter on port : " + aceServerConfig.getPort());
future.channel().closeFuture().sync();
} finally {
close();
}
}
Receiver.java 文件源码
项目:neoscada
阅读 33
收藏 0
点赞 0
评论 0
public Receiver ( final ReceiverHandlerFactory factory, final SocketAddress addr )
{
this.factory = factory;
this.bossGroup = new NioEventLoopGroup ();
this.workerGroup = new NioEventLoopGroup ();
this.bootstrap = new ServerBootstrap ();
this.bootstrap.group ( this.bossGroup, this.workerGroup );
this.bootstrap.channel ( NioServerSocketChannel.class );
this.bootstrap.option ( ChannelOption.SO_BACKLOG, 5 );
this.bootstrap.option ( ChannelOption.SO_REUSEADDR, true );
this.bootstrap.childHandler ( new ChannelInitializer<SocketChannel> () {
@Override
protected void initChannel ( final SocketChannel ch ) throws Exception
{
handleInitChannel ( ch );
}
} );
this.channel = this.bootstrap.bind ( addr ).channel ();
logger.info ( "Receiver running ..." );
}
NettyServerServiceImpl.java 文件源码
项目:sds
阅读 36
收藏 0
点赞 0
评论 0
@Override
public synchronized void start() {
bossGroup = new NioEventLoopGroup(); // (1)
workerGroup = new NioEventLoopGroup();
try {
b = new ServerBootstrap(); // (2)
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new SocketServerChannelInitializer(heartTime,socketService,applicationContext));
// Bind and start to accept incoming connections.
b.bind(port);
logger.info("socket: "+port+" starting....");
// Wait until the server socket is closed.
// In this example, this does not happen, but you can do that to gracefully
} catch (Exception e) {
e.printStackTrace();
}
}
Server.java 文件源码
项目:message-broker
阅读 38
收藏 0
点赞 0
评论 0
private ChannelFuture bindToPlainSocket() throws InterruptedException {
String hostname = configuration.getHostName();
int port = Integer.parseInt(configuration.getPlain().getPort());
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new SocketChannelInitializer(ioExecutors))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);
// Bind and start to accept incoming connections.
ChannelFuture future = b.bind(hostname, port).sync();
LOGGER.info("Listening AMQP on " + hostname + ":" + port);
return future;
}
Server.java 文件源码
项目:message-broker
阅读 29
收藏 0
点赞 0
评论 0
private ChannelFuture bindToSslSocket()
throws InterruptedException, CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException,
KeyStoreException, KeyManagementException, IOException {
String hostname = configuration.getHostName();
int port = Integer.parseInt(configuration.getSsl().getPort());
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new SslSocketChannelInitializer(ioExecutors, new SslHandlerFactory(configuration)))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);
// Bind and start to accept incoming connections.
ChannelFuture future = b.bind(hostname, port).sync();
LOGGER.info("Listening AMQP/" + configuration.getSsl().getProtocol() + " on " + hostname + ":" + port);
return future;
}
Http2TestServer.java 文件源码
项目:chromium-net-for-android
阅读 32
收藏 0
点赞 0
评论 0
public void run() {
try {
// Configure the server.
EventLoopGroup group = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(group)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new Http2ServerInitializer(mSslCtx));
sServerChannel = b.bind(PORT).sync().channel();
Log.i(TAG, "Netty HTTP/2 server started on " + getServerUrl());
sBlock.open();
sServerChannel.closeFuture().sync();
} finally {
group.shutdownGracefully();
}
Log.i(TAG, "Stopped Http2TestServerRunnable!");
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
NetworkServer.java 文件源码
项目:cr-private-server
阅读 31
收藏 0
点赞 0
评论 0
public void start() {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(new PlayerInitializer(this));
try {
channel = bootstrap.bind(server.getConfig().get("server.port").getAsShort()).sync().channel();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
ServerMain.java 文件源码
项目:netty-socks
阅读 32
收藏 0
点赞 0
评论 0
public void start() throws InterruptedException {
EventLoopGroup acceptors = new NioEventLoopGroup(socksProperties.getAcceptors());
EventLoopGroup workers = new NioEventLoopGroup();
EventLoopGroup forwarders = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(acceptors, workers)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, socksProperties.getBacklog())
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, socksProperties.getConnectTimeoutMillis())
.childHandler(new Socks5WorkerChannelInitializer(socksProperties, forwarders));
Address address = socksProperties.getListen();
ChannelFuture future = bootstrap.bind(address.getHost(), address.getPort()).sync();
future.channel().closeFuture().sync();
} finally {
forwarders.shutdownGracefully();
workers.shutdownGracefully();
acceptors.shutdownGracefully();
}
}
NettyServer.java 文件源码
项目:ClusterDeviceControlPlatform
阅读 30
收藏 0
点赞 0
评论 0
@Override
public void run(String... args) throws Exception {
NioEventLoopGroup group = new NioEventLoopGroup();
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(group)
.channel(NioServerSocketChannel.class)
.childHandler(serverChannelInitializer);
ChannelFuture channelFuture = bootstrap.bind(new InetSocketAddress(30232));
channelFuture.addListener(future -> {
if (future.isSuccess()) {
logger.info("「Netty」服务器启动成功");
} else {
logger.info("「Netty」服务器启动失败");
}
});
}
HttpServer.java 文件源码
项目:mapsforge-web
阅读 35
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup,workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new HttpServer());
ChannelFuture channelFuture = serverBootstrap
.bind(new InetSocketAddress("0.0.0.0", PORT))
.sync();
channelFuture.channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
EchoServer.java 文件源码
项目:AlphaLibary
阅读 30
收藏 0
点赞 0
评论 0
public void start() {
ServerBootstrap b = new ServerBootstrap();
b.group(workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
System.out.println("New client connected! (" + socketChannel.localAddress() + ")");
socketChannel.pipeline().addLast(new StringEncoder()).addLast(new StringEncoder()).addLast(new EchoServerHandler());
}
});
f = b.bind(port);
}
NettyServer.java 文件源码
项目:Razor
阅读 31
收藏 0
点赞 0
评论 0
private void startServer() throws Exception {
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(masterGroup, slaveGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new HttpServerInitializer(razor))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);
this.channel = bootstrap.bind(env.get(ENV_KEY_SERVER_HOST, DEFAULT_SERVER_HOST), env.getInt(ENV_KEY_SERVER_PORT, DEFAULT_SERVER_PORT)).sync().channel();
log.info("{} started and listen on {}", HttpServerHandler.class.getName(), channel.localAddress());
} catch (final InterruptedException e){
log.error("Netty server startup failed, error: {}", e.getMessage());
}
}
DovakinMQServer.java 文件源码
项目:DovakinMQ
阅读 31
收藏 0
点赞 0
评论 0
public void start(){
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(workerGroup,bossGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new TCPHandlerInitializer(this))
.option(ChannelOption.SO_BACKLOG, 512)
.childOption(ChannelOption.SO_KEEPALIVE, true);
Channel serverChannel = bootstrap.bind(new InetSocketAddress(port)).channel();
ChannelFuture future = serverChannel.closeFuture();
try {
System.out.println("MQTT服务器已启动...");
future.sync();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
SdkServer.java 文件源码
项目:DistributedID
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void init() {
super.init();
b.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_BACKLOG, 1024)
.localAddress(new InetSocketAddress(port))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(defLoopGroup,
new SdkServerDecoder(12), // 自定义解码器
new SdkServerEncoder(), // 自定义编码器
new SdkServerHandler(snowFlake) // 自定义处理器
);
}
});
}
InkServer.java 文件源码
项目:Ink
阅读 32
收藏 0
点赞 0
评论 0
public void start() {
EventLoopGroup boss = new NioEventLoopGroup(1);
EventLoopGroup worker = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(boss,worker)
.channel(NioServerSocketChannel.class)
.childHandler(new HttpChannelInitializer(list));
ChannelFuture future = bootstrap.bind(port).sync();
log.info("start listen in port {}", port);
future.channel().closeFuture().sync();
} catch (Exception e ) {
e.printStackTrace();
} finally {
boss.shutdownGracefully();
worker.shutdownGracefully();
}
}
RightTimeServer.java 文件源码
项目:netty_op
阅读 27
收藏 0
点赞 0
评论 0
/**
*@description 监听指定端口
*@time 创建时间:2017年7月21日下午3:50:26
*@param port
*@throws InterruptedException
*@author dzn
*/
public void bind(int port) throws InterruptedException{
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap server = new ServerBootstrap();
server.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChildChannelHandler());
ChannelFuture cf = server.bind(port).sync();
System.out.println("服务器已启动, 监控端口号为 : " + port);
cf.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
ErrorTimeServer.java 文件源码
项目:netty_op
阅读 30
收藏 0
点赞 0
评论 0
/**
*@description 监听指定端口
*@time 创建时间:2017年7月21日下午3:50:26
*@param port
*@throws InterruptedException
*@author dzn
*/
public void bind(int port) throws InterruptedException{
//分配任务线程池
EventLoopGroup bossGroup = new NioEventLoopGroup();
//执行任务线程池
EventLoopGroup workGroup = new NioEventLoopGroup();
try{
//netty Server端
ServerBootstrap server = new ServerBootstrap();
server.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChildChannelHandler());
//启动netty服务器
ChannelFuture cf = server.bind(port).sync();
System.out.println("服务器已启动, 监控端口号为 : " + port);
//等待服务器端关闭
cf.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
TimeServer.java 文件源码
项目:netty_op
阅读 44
收藏 0
点赞 0
评论 0
/**
*@description 监听指定端口
*@time 创建时间:2017年7月21日下午3:50:26
*@param port
*@throws InterruptedException
*@author dzn
*/
public void bind(int port) throws InterruptedException{
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap server = new ServerBootstrap();
server.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChildChannelHandler());
ChannelFuture cf = server.bind(port).sync();
System.out.println("服务器已启动, 监控端口号为 : " + port);
cf.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
Socks5ProxyServer.java 文件源码
项目:probe
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void start(Config config) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
int port = config.getPort();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
.childHandler(new SocksServerInitializer(config));
log.info("Socks5 server bind port: {}", port);
b.bind(port).sync().channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}