|
@ -91,14 +91,8 @@ 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); |
|
|
|
|
|
try { |
|
|
|
|
|
channel.writeAndFlush(byteBuf); |
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("TCP发送请求失败: {}", request, e); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
channel.writeAndFlush(Unpooled.copiedBuffer(request, CharsetUtil.UTF_8)); |
|
|
|
|
|
return true; |
|
|
} else { |
|
|
} else { |
|
|
log.error("TCP服务未连接,无法发送请求: {}", request); |
|
|
log.error("TCP服务未连接,无法发送请求: {}", request); |
|
|
return false; |
|
|
return false; |
|
|