实际上,我可以使用netty发送和接收String对象,但是我无法发送任何对象,如ISO消息,我无法找到原因。 这是客户端如何将ISO消息对象从客户端发送到java中的Netty服务器
public void start() {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap bootstrap = new Bootstrap().group(group)
.channel(NioSocketChannel.class)
.handler(new ClientAdapterInitializer());
Channel channel = bootstrap.connect(server, port).sync().channel();
channel.write("Hi\n");
IsoMessage o = new IsoMessage();
o.setType(0200);
o.setBinary(true);
Teacher t = new Teacher(1, "hhhhh");
//ObjectEncoder encoder = new ObjectEncoder();
o.setField(3, new IsoValue(IsoType.BINARY, group, 1100));
channel.write(t);
channel.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
// group.shutdownGracefully();
}
}
和服务器@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { IsoMessage is=(IsoMessage) msg; System.out.println(""+is.getType()); //ByteBuf byteBuf = (ByteBuf) is; //System.out.println(""+byteBuf.toString()); //logger.info("message : {} " + //byteBuf.toString(Charset.defaultCharset())); channels.writeAndFlush(msg); }
你的管道是怎么看的? – Ferrybig
直到现在我没有提供它 –