简体   繁体   English

如何在Java中将ISO消息对象从客户端发送到Netty服务器

[英]How to send ISO message Object from client to Netty server in java

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 . 实际上,我可以使用netty发送和接收String对象,但是我无法发送任何对象(如ISO消息),而且我也找不到原因。 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); } @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. 您应该检查writeChannelFuture告诉您什么。 It will most likely be failed with an exception that will tell you more why it not worked 它很可能会失败,并带有一个异常,它将告诉您更多为什么它不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM