为了账号安全,请及时绑定邮箱和手机立即绑定

socketChannel多次注册疑问

请问一下在处理readHandler方法中为什么要把socketChannel再次注册到selector上,不是已经注册过了么


String str = "";
//读取的字节大于0
while(channel.read(buffer) > 0){
    //将buffer转换为读模式
    buffer.flip();

    str += Charset.forName("UTF-8").decode(buffer);
}

//将channel再次注册到selector上
channel.register(selector,SelectionKey.OP_READ);

if(str.length() > 0){
    //广播给其它客户端
    broadcast(selector,channel,str);
}


正在回答

1 回答

123456

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

socketChannel多次注册疑问

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号