Actually i can send and receive String object with netty but i can not send any object like ISO message and i can not find the reason for that . this is start method in client
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();
}
}
and in server @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); }
@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); }
You should check what the ChannelFuture
of the write
is telling you. It will most likely be failed with an exception that will tell you more why it not worked
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.