第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Netty - 客戶端讀寫操作

Netty - 客戶端讀寫操作

慕森王 2021-10-27 09:51:27
我正在嘗試從服務(wù)器發(fā)送和接收消息。服務(wù)器已建立在遠(yuǎn)程環(huán)境中。服務(wù)器有一些特定的信號代碼,例如:這些代碼作為字節(jié)發(fā)送。在這一點上,問題開始了。當(dāng)客戶端與服務(wù)器連接時,服務(wù)器立即發(fā)送 100000050 并在幾毫秒后發(fā)送 10000051。我應(yīng)該在收到 10000051 后發(fā)送 10000060 但我不知道如何發(fā)送。客戶端.JAVApublic static void main(String[] args) throws Exception {        EventLoopGroup group = new NioEventLoopGroup();        try {            Bootstrap clientBootstrap = new Bootstrap();            clientBootstrap.group(group);            clientBootstrap.channel(NioSocketChannel.class);            clientBootstrap.remoteAddress(new InetSocketAddress("10.80.15.70", 55102));            clientBootstrap.handler(new ChannelInitializer<SocketChannel>() {                protected void initChannel(SocketChannel socketChannel) throws Exception {                    socketChannel.pipeline().addLast(new ClientHandler());                }            });            ChannelFuture channelFuture = clientBootstrap.connect().sync();            channelFuture.channel().closeFuture().sync();        }        finally {            group.shutdownGracefully().sync();        }    }客戶端處理程序.JAVApublic class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> {    private static final Logger LOGGER = Logger.getLogger( ClientHandler.class.getName() );    @Override    public void channelActive(ChannelHandlerContext channelHandlerContext){        //System.out.println("\nhelloo");        //channelHandlerContext.writeAndFlush(Unpooled.copiedBuffer("Netty Rocks!", CharsetUtil.UTF_8));        byte [] test = new byte[9];        test[0] = 0;        test[1] = 6;        test[2] = 0;        test[3] = 0;        test[4] = 0;        test[5] = 0;        test[6] = 0;        test[7] = 0;        test[8] = 1;        //byte [] message = "100000060".getBytes();        channelHandlerContext.writeAndFlush(test);    }    @Override    public void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf in) {        System.out.println("Client received: " + in.toString(CharsetUtil.UTF_8));    }
查看完整描述

1 回答

?
BIG陽

TA貢獻(xiàn)1859條經(jīng)驗 獲得超6個贊

您可以通過更新您的channelRead0方法來檢查收到的消息,然后在收到您正在尋找的消息時回復(fù)。


@Override

public void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf in) {

    String message = in.toString(CharsetUtil.UTF_8);


    if (message.equals("10000051")) { //Now do what you were doing in channel active

        byte [] test = new byte[9];


        test[0] = 0;

        test[1] = 6;

        test[2] = 0;

        test[3] = 0;

        test[4] = 0;

        test[5] = 0;

        test[6] = 0;

        test[7] = 0;

        test[8] = 1;



        //byte [] message = "100000060".getBytes();

        channelHandlerContext.writeAndFlush(test);

    }

}


查看完整回答
反對 回復(fù) 2021-10-27
  • 1 回答
  • 0 關(guān)注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號