A SpringBoot project will call a client program implemented in Netty when an address is accessed. The client will communicate with the server also implemented in Netty and get the result, and then return the result in Json format. This is the whole process.
now when I am running locally, I have encountered this error on the SpringBoot side:
java.net.ConnectException: Connection refused: no further information: / 127.0.0.1 br 8080
but the operation phenomenon is normal, the result of the web page is returned, and the server is running normally. I want to know where this problem lies, whether it has a big impact, and how to solve it. Thank you.
Server part code:
public void bind(int port) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChildChannelHandler());
ChannelFuture f = b.bind(port).sync();
f.channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
private class ChildChannelHandler extends ChannelInitializer<SocketChannel> {
@Override
protected void initChannel(SocketChannel arg0) throws Exception {
arg0.pipeline().addLast(new LineBasedFrameDecoder(1024));
arg0.pipeline().addLast(new StringDecoder());
arg0.pipeline().addLast(new TimeServerHandler());
}
}
client part code:
public Response connect(int port, String host) throws Exception{
EventLoopGroup group = new NioEventLoopGroup();
try{
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception{
ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
ch.pipeline().addLast(new ResponseDecoder(Response.class));
ch.pipeline().addLast(TimeClient.this);
}
});
ChannelFuture f = b.connect(host, port).sync();
f.channel().closeFuture().sync();
return response;
}finally {
group.shutdownGracefully();
}
}
@Override
@SuppressWarnings("unchecked")
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception{
this.response = (Response) msg;
ctx.channel().close();
}