Commit 1f4db17f authored by duanruiming's avatar duanruiming

[update] 绑定本地固定端口

parent 6889e078
...@@ -41,8 +41,9 @@ public class NettyClient { ...@@ -41,8 +41,9 @@ public class NettyClient {
bootstrap.group(group) bootstrap.group(group)
.channel(NioDatagramChannel.class) .channel(NioDatagramChannel.class)
.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(65535)) .option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(65535))
.localAddress(5051) // .localAddress(new InetSocketAddress(5051))
.remoteAddress(new InetSocketAddress("10.102.1.204", 5050)) // 绑定bending端口
.remoteAddress(new InetSocketAddress(5051))
.handler(new ChannelInitializer<NioDatagramChannel>() { .handler(new ChannelInitializer<NioDatagramChannel>() {
@Override @Override
protected void initChannel(NioDatagramChannel datagramChannel) { protected void initChannel(NioDatagramChannel datagramChannel) {
...@@ -50,7 +51,7 @@ public class NettyClient { ...@@ -50,7 +51,7 @@ public class NettyClient {
.addLast(new NettyServerHandler(threadPoolExecutor)); .addLast(new NettyServerHandler(threadPoolExecutor));
} }
}); });
ChannelFuture channelFuture = bootstrap.bind().sync(); ChannelFuture channelFuture = bootstrap.bind(5050).sync();
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
group.shutdownGracefully(); group.shutdownGracefully();
channelFuture.channel().closeFuture().syncUninterruptibly(); channelFuture.channel().closeFuture().syncUninterruptibly();
......
...@@ -81,6 +81,11 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPack ...@@ -81,6 +81,11 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPack
} }
} }
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
}
private CommandPojo getCommandPojo(String key, String data) { private CommandPojo getCommandPojo(String key, String data) {
CrossInfoPO crossInfo = crossInfoCache.getCrossInfo(key); CrossInfoPO crossInfo = crossInfoCache.getCrossInfo(key);
CommandPojo commandPojo = new CommandPojo(); CommandPojo commandPojo = new CommandPojo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment