netty 发送websocket数据失败

如此美丽的你 2020-08-29 10:03:52
在handler 类里面

/**
* 有数据时触发
*/
@Override
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) throws Exception {

}

/**
* 建立连接后第一个执行
*/
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
ctx.channel().writeAndFlush(new TextWebSocketFrame("hello world"));
}



前端接收不到数据 ,在函数channelRead0里面发送就可以收到 这是怎么回事呢
...全文
4397 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Nuanan- 2020-09-27
  • 打赏
  • 举报
回复
应该是可以收到的,第一次连接可以发出去的
如此美丽的你 2020-08-31
  • 打赏
  • 举报
回复
引用 1 楼 tianfang 的回复:
你的channelRead0中的代码呢


不影响后面的发送吗吧 两个函数测试的时候都是这句
ctx.channel().writeAndFlush(new TextWebSocketFrame("hello world"));
tianfang 2020-08-30
  • 打赏
  • 举报
回复
你的channelRead0中的代码呢

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧