Commit 4924ed56 authored by duanruiming's avatar duanruiming

[update] 配置端口常量

parent 1f4db17f
......@@ -4,6 +4,7 @@ import net.wanji.com.netty.NettyClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
......@@ -25,6 +26,10 @@ public class Application implements ApplicationRunner {
@Qualifier(value = "threadPoolExecutor")
@Autowired
static ThreadPoolTaskExecutor threadPoolExecutor;
@Value("${portParam.localPort}")
int localPort;
@Value("${portParam.remotePort}")
int remoteProt;
public static void main(String[] args) {
......@@ -33,6 +38,6 @@ public class Application implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
NettyClient.start(5050, threadPoolExecutor);
NettyClient.start(localPort, remoteProt, threadPoolExecutor);
}
}
......@@ -35,15 +35,15 @@ public class NettyClient {
/**
* 建立连接
*/
public static void start(int port, ThreadPoolTaskExecutor threadPoolExecutor) throws InterruptedException {
public static void start(int localPort, int remotePort, ThreadPoolTaskExecutor threadPoolExecutor) throws InterruptedException {
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group)
.channel(NioDatagramChannel.class)
.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(65535))
// .localAddress(new InetSocketAddress(5051))
// 绑定bending端口
.remoteAddress(new InetSocketAddress(5051))
// 绑定端口
.remoteAddress(new InetSocketAddress(remotePort))
.handler(new ChannelInitializer<NioDatagramChannel>() {
@Override
protected void initChannel(NioDatagramChannel datagramChannel) {
......@@ -51,13 +51,13 @@ public class NettyClient {
.addLast(new NettyServerHandler(threadPoolExecutor));
}
});
ChannelFuture channelFuture = bootstrap.bind(5050).sync();
ChannelFuture channelFuture = bootstrap.bind(localPort).sync();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
group.shutdownGracefully();
channelFuture.channel().closeFuture().syncUninterruptibly();
log.warn("server is closed");
}));
log.info("udp application is running. binding port is {}", port);
log.info("udp application is running. binding port is {}", remotePort);
NettyClient.udpChannelFuture = channelFuture;
}
......
......@@ -67,3 +67,7 @@ threadPoolConfig:
queueCapacity: 200
keepAliveTime: 6000
allowCoreTimeOut: false
#东土通讯端口配置
portParam:
localPort: 5051
remotePort: 5050
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