|
@ -90,8 +90,12 @@ public class TcpClient { |
|
|
public boolean send(String request) { |
|
|
public boolean send(String request) { |
|
|
if (channel != null && channel.isActive()) { |
|
|
if (channel != null && channel.isActive()) { |
|
|
ByteBuf byteBuf = Unpooled.copiedBuffer(request, CharsetUtil.UTF_8); |
|
|
ByteBuf byteBuf = Unpooled.copiedBuffer(request, CharsetUtil.UTF_8); |
|
|
channel.writeAndFlush(byteBuf); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
channel.writeAndFlush(byteBuf); |
|
|
|
|
|
return true; |
|
|
|
|
|
} finally { |
|
|
|
|
|
byteBuf.release(); // 确保释放资源 |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
log.error("TCP服务未连接,无法发送请求: {}", request); |
|
|
log.error("TCP服务未连接,无法发送请求: {}", request); |
|
|
return false; |
|
|
return false; |
|
|