普通的TCP SERVER工具能发送信息到netty的客户端,但netty客户端发送的数据,服务端收不到,不知什么原因?
但是netyy client与netty server又是正常的
配置代码
public boolean ConnectServer(ChannelHandler channelhandler) {
group = new NioEventLoopGroup();
try {
bootstrap = new Bootstrap();
bootstrap.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(channelhandler);
ch.pipeline().addLast(new OutBoard());
}
});
future = bootstrap.connect(HOST, PORT).sync();
future.channel().write("ffffsfsdfds");
//future.channel().closeFuture().sync();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return false;
}
return true;
}
Netty
你需要创建缓冲区,然后将字符串写入到缓冲区,然后writer缓冲区! 简单的说 字符串不是这么发送的 百度一下 随便找个发送字符串的demo